Created
June 6, 2012 14:37
-
-
Save pifleo/2882280 to your computer and use it in GitHub Desktop.
Devise custom mailer layout with inline attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# app/views/devise_custom_mailer/confirmation_instructions.html.haml | |
%p | |
= t('devise.mailer.welcome', :email => @resource.email) | |
%p= t('devise.mailer.confirmation_instructions.msg') | |
%p= link_to t('devise.mailer.confirmation_instructions.link'), confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) | |
%br | |
- if @resource.tmp | |
%p | |
= t('devise.mailer.confirmation_instructions.password_instruction', :password => @resource.tmp) | |
= t('devise.mailer.confirmation_instructions.password_instruction2') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/devise.rb | |
... | |
Devise.setup do |config| | |
... | |
# Configure the class responsible to send e-mails. | |
# config.mailer = "Devise::Mailer" | |
config.mailer = "DeviseCustomMailer" | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/mailers/devise_custom_mailer.rb | |
class DeviseCustomMailer < Devise::Mailer | |
if self.included_modules.include?(AbstractController::Callbacks) | |
raise "You've already included AbstractController::Callbacks, remove this line." | |
else | |
include AbstractController::Callbacks | |
end | |
before_filter :add_inline_attachment! | |
def confirmation_instructions(record) | |
super | |
end | |
def reset_password_instructions(record) | |
super | |
end | |
def unlock_instructions(record) | |
super | |
end | |
private | |
def add_inline_attachment! | |
attachments.inline['header.jpg'] = File.read(File.join(Rails.root,'app','assets','images','mail','home.jpg')) | |
attachments.inline['footer.jpg'] = File.read(File.join(Rails.root,'app','assets','images','mail','foot.jpg')) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# app/views/layouts/notifier.html.haml | |
.header-mail{:style => "background-color:#fefefe;display:inline;float:left;font:normal 11px verdana;margin:0px;padding:10px;width:579px", :align => :center} | |
= image_tag(attachments['header.jpg'].try(:url), :alt => "header", :height => "105px", :width => "361px") | |
%br | |
.body-mail{:style => "background-color:#efefef;display:inline;float:left;font:normal 11px verdana;margin:0px;padding:10px;width:579px"} | |
= yield | |
%p{:style => "margin-top:30px"} | |
%i L'équipe XXXXX | |
%p | |
PS : merci de ne pas répondre directement à cet e-mail, envoyé automatiquement | |
%br | |
.footer-mail | |
= image_tag(attachments['footer.jpg'].try(:url), :alt => "footer") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# app/views/devise_custom_mailer/reset_password_instructions.html.haml | |
%p | |
Hello #{@resource.email}! | |
%p Someone has requested a link to change your password, and you can do this through the link below. | |
%p= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @resource.reset_password_token) | |
%p If you didn't request this, please ignore this email. | |
%p Your password won't change until you access the link above and create a new one. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-# app/views/devise_custom_mailer/unlock_instructions.html.haml | |
%p | |
Hello #{@resource.email}! | |
%p Your account has been locked due to an excessive amount of unsuccessful sign in attempts. | |
%p Click the link below to unlock your account: | |
%p= link_to 'Unlock my account', unlock_url(@resource, :unlock_token => @resource.unlock_token) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment