Skip to content
This repository
Browse code

Accept mail options in Devise::Mailer and deprecate headers_for

  • Loading branch information...
commit 19b5bcbe0fe63489f67eaf42aefea382d45cc1d7 1 parent 7c8f636
José Valim authored January 04, 2013
4  CHANGELOG.rdoc
Source Rendered
... ...
@@ -1,3 +1,7 @@
  1
+* backwards incompatibility changes
  2
+  * `headers_for` is deprecated, customize the mailer directly instead
  3
+  * All mailer methods now expect a second argument with delivery options
  4
+
1 5
 == 2.2.0.rc
2 6
 
3 7
 * important changes
12  app/mailers/devise/mailer.rb
... ...
@@ -1,15 +1,15 @@
1 1
 class Devise::Mailer < ::ActionMailer::Base
2 2
   include Devise::Mailers::Helpers
3 3
 
4  
-  def confirmation_instructions(record)
5  
-    devise_mail(record, :confirmation_instructions)
  4
+  def confirmation_instructions(record, opts={})
  5
+    devise_mail(record, :confirmation_instructions, opts)
6 6
   end
7 7
 
8  
-  def reset_password_instructions(record)
9  
-    devise_mail(record, :reset_password_instructions)
  8
+  def reset_password_instructions(record, opts={})
  9
+    devise_mail(record, :reset_password_instructions, opts)
10 10
   end
11 11
 
12  
-  def unlock_instructions(record)
13  
-    devise_mail(record, :unlock_instructions)
  12
+  def unlock_instructions(record, opts={})
  13
+    devise_mail(record, :unlock_instructions, opts)
14 14
   end
15 15
 end
13  lib/devise/mailers/helpers.rb
@@ -11,9 +11,9 @@ module Helpers
11 11
       protected
12 12
 
13 13
       # Configure default email options
14  
-      def devise_mail(record, action)
  14
+      def devise_mail(record, action, opts={})
15 15
         initialize_from_record(record)
16  
-        mail headers_for(action)
  16
+        mail headers_for(action, opts)
17 17
       end
18 18
 
19 19
       def initialize_from_record(record)
@@ -25,16 +25,19 @@ def devise_mapping
25 25
         @devise_mapping ||= Devise.mappings[scope_name]
26 26
       end
27 27
 
28  
-      def headers_for(action)
  28
+      def headers_for(action, opts)
29 29
         headers = {
30 30
           :subject       => translate(devise_mapping, action),
31 31
           :to            => resource.email,
32 32
           :from          => mailer_sender(devise_mapping),
33 33
           :reply_to      => mailer_reply_to(devise_mapping),
34  
-          :template_path => template_paths
35  
-        }
  34
+          :template_path => template_paths,
  35
+          :template_name => action
  36
+        }.merge(opts)
36 37
 
37 38
         if resource.respond_to?(:headers_for)
  39
+          ActiveSupport::Deprecation.warn "Calling headers_for in the model is no longer supported. " <<
  40
+            "Please customize your mailer instead."
38 41
           headers.merge!(resource.headers_for(action))
39 42
         end
40 43
 
8  lib/devise/models/authenticatable.rb
@@ -93,10 +93,6 @@ def inactive_message
93 93
       def authenticatable_salt
94 94
       end
95 95
 
96  
-      def headers_for(name)
97  
-        {}
98  
-      end
99  
-
100 96
       array = %w(serializable_hash)
101 97
       # to_xml does not call serializable_hash on 3.1
102 98
       array << "to_xml" if Rails::VERSION::STRING[0,3] == "3.1"
@@ -159,8 +155,8 @@ def devise_mailer
159 155
       #       end
160 156
       #     end
161 157
       #
162  
-      def send_devise_notification(notification)
163  
-        devise_mailer.send(notification, self).deliver
  158
+      def send_devise_notification(notification, opts={})
  159
+        devise_mailer.send(notification, self, opts).deliver
164 160
       end
165 161
 
166 162
       def downcase_keys
12  lib/devise/models/confirmable.rb
@@ -87,7 +87,9 @@ def send_confirmation_instructions
87 87
         @reconfirmation_required = false
88 88
 
89 89
         generate_confirmation_token! if self.confirmation_token.blank?
90  
-        send_devise_notification(:confirmation_instructions)
  90
+
  91
+        opts = pending_reconfirmation? ? { :to => unconfirmed_email } : { }
  92
+        send_devise_notification(:confirmation_instructions, opts)
91 93
       end
92 94
 
93 95
       # Resend confirmation token. This method does not need to generate a new token.
@@ -123,14 +125,6 @@ def skip_reconfirmation!
123 125
         @bypass_postpone = true
124 126
       end
125 127
 
126  
-      def headers_for(action)
127  
-        headers = super
128  
-        if action == :confirmation_instructions && pending_reconfirmation?
129  
-          headers[:to] = unconfirmed_email
130  
-        end
131  
-        headers
132  
-      end
133  
-
134 128
       protected
135 129
 
136 130
         # A callback method used to deliver confirmation

1 note on commit 19b5bcb

Lucas Mazza
Collaborator

:heart:

Romain Pechayre

Hi,

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

Vasiliy Ermolovich

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

Romain Pechayre
Vasiliy Ermolovich
Please sign in to comment.
Something went wrong with that request. Please try again.