Skip to content

Commit

Permalink
Accept mail options in Devise::Mailer and deprecate headers_for
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim committed Jan 4, 2013
1 parent 7c8f636 commit 19b5bcb
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,7 @@
* backwards incompatibility changes
* `headers_for` is deprecated, customize the mailer directly instead
* All mailer methods now expect a second argument with delivery options

== 2.2.0.rc

* important changes
Expand Down
12 changes: 6 additions & 6 deletions app/mailers/devise/mailer.rb
@@ -1,15 +1,15 @@
class Devise::Mailer < ::ActionMailer::Base
include Devise::Mailers::Helpers

def confirmation_instructions(record)
devise_mail(record, :confirmation_instructions)
def confirmation_instructions(record, opts={})
devise_mail(record, :confirmation_instructions, opts)
end

def reset_password_instructions(record)
devise_mail(record, :reset_password_instructions)
def reset_password_instructions(record, opts={})
devise_mail(record, :reset_password_instructions, opts)
end

def unlock_instructions(record)
devise_mail(record, :unlock_instructions)
def unlock_instructions(record, opts={})
devise_mail(record, :unlock_instructions, opts)
end
end
13 changes: 8 additions & 5 deletions lib/devise/mailers/helpers.rb
Expand Up @@ -11,9 +11,9 @@ module Helpers
protected

# Configure default email options
def devise_mail(record, action)
def devise_mail(record, action, opts={})
initialize_from_record(record)
mail headers_for(action)
mail headers_for(action, opts)
end

def initialize_from_record(record)
Expand All @@ -25,16 +25,19 @@ def devise_mapping
@devise_mapping ||= Devise.mappings[scope_name]
end

def headers_for(action)
def headers_for(action, opts)
headers = {
:subject => translate(devise_mapping, action),
:to => resource.email,
:from => mailer_sender(devise_mapping),
:reply_to => mailer_reply_to(devise_mapping),
:template_path => template_paths
}
:template_path => template_paths,
:template_name => action
}.merge(opts)

if resource.respond_to?(:headers_for)
ActiveSupport::Deprecation.warn "Calling headers_for in the model is no longer supported. " <<
"Please customize your mailer instead."
headers.merge!(resource.headers_for(action))
end

Expand Down
8 changes: 2 additions & 6 deletions lib/devise/models/authenticatable.rb
Expand Up @@ -93,10 +93,6 @@ def inactive_message
def authenticatable_salt
end

def headers_for(name)
{}
end

array = %w(serializable_hash)
# to_xml does not call serializable_hash on 3.1
array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
Expand Down Expand Up @@ -159,8 +155,8 @@ def devise_mailer
# end
# end
#
def send_devise_notification(notification)
devise_mailer.send(notification, self).deliver
def send_devise_notification(notification, opts={})
devise_mailer.send(notification, self, opts).deliver

This comment has been minimized.

Copy link
@rpechayr

rpechayr Jan 23, 2013

Contributor

Hi,

This call does not work for Rails 3.1.10. I think devise 2.2 does not work priori to rails 3.2.

This comment has been minimized.

Copy link
@nashby

nashby Jan 23, 2013

Collaborator

Hi, could you please show a backtrace (paste it to the gist)?

This comment has been minimized.

Copy link
@rpechayr

rpechayr via email Jan 23, 2013

Contributor

This comment has been minimized.

Copy link
@nashby

nashby via email Jan 23, 2013

Collaborator
end

def downcase_keys
Expand Down
12 changes: 3 additions & 9 deletions lib/devise/models/confirmable.rb
Expand Up @@ -87,7 +87,9 @@ def send_confirmation_instructions
@reconfirmation_required = false

generate_confirmation_token! if self.confirmation_token.blank?
send_devise_notification(:confirmation_instructions)

opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
send_devise_notification(:confirmation_instructions, opts)
end

# Resend confirmation token. This method does not need to generate a new token.
Expand Down Expand Up @@ -123,14 +125,6 @@ def skip_reconfirmation!
@bypass_postpone = true
end

def headers_for(action)
headers = super
if action == :confirmation_instructions && pending_reconfirmation?
headers[:to] = unconfirmed_email
end
headers
end

protected

# A callback method used to deliver confirmation
Expand Down

1 comment on commit 19b5bcb

@lucasmazza
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Please sign in to comment.