Permalink
Browse files

Accept mail options in Devise::Mailer and deprecate headers_for

  • Loading branch information...
1 parent 7c8f636 commit 19b5bcbe0fe63489f67eaf42aefea382d45cc1d7 @josevalim josevalim committed Jan 4, 2013
View
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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"
@@ -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
@rpechayr
rpechayr Jan 23, 2013

Hi,

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

@nashby
nashby Jan 23, 2013 collaborator

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

@rpechayr
rpechayr via email Jan 23, 2013
@nashby
nashby via email Jan 23, 2013 collaborator
end
def downcase_keys
@@ -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.
@@ -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

1 comment on commit 19b5bcb

@lucasmazza
Member

❤️

Please sign in to comment.