Skip to content
This repository
Browse code

Allow the mailer class to be configured.

  • Loading branch information...
commit a2f84852af504df8c93c0b0f1afff7f76601b400 1 parent c4a4032
José Valim josevalim authored
1  CHANGELOG.rdoc
Source Rendered
@@ -6,6 +6,7 @@
6 6 * Added authenticate(scope) support in routes (by github.com/wildchild)
7 7 * Added after_update_path_for to registrations controller (by github.com/thedelchop)
8 8 * Added anybody_signed_in? helper (by github.com/SSDany)
  9 + * Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
9 10
10 11 * bug fix
11 12 * confirmation_required? is properly honored on active? calls. (by github.com/paulrosania)
12 lib/devise.rb
... ... @@ -1,4 +1,5 @@
1 1 require 'active_support/core_ext/numeric/time'
  2 +require 'active_support/dependencies'
2 3
3 4 module Devise
4 5 autoload :FailureApp, 'devise/failure_app'
@@ -161,6 +162,17 @@ def self.setup
161 162 yield self
162 163 end
163 164
  165 + # Get the mailer class from the mailer reference object.
  166 + def self.mailer
  167 + @@mailer_ref.get
  168 + end
  169 +
  170 + # Set the mailer reference object to access the mailer.
  171 + def self.mailer=(class_name)
  172 + @@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
  173 + end
  174 + self.mailer = "Devise::Mailer"
  175 +
164 176 # Register a model in Devise. You can call this manually if you don't want
165 177 # to use devise routes. Check devise_for in routes to know which options
166 178 # are available.
2  lib/devise/models/confirmable.rb
@@ -51,7 +51,7 @@ def confirmed?
51 51 # Send confirmation instructions by email
52 52 def send_confirmation_instructions
53 53 generate_confirmation_token if self.confirmation_token.nil?
54   - ::Devise::Mailer.confirmation_instructions(self).deliver
  54 + ::Devise.mailer.confirmation_instructions(self).deliver
55 55 end
56 56
57 57 # Resend confirmation token. This method does not need to generate a new token.
2  lib/devise/models/lockable.rb
@@ -49,7 +49,7 @@ def access_locked?
49 49
50 50 # Send unlock instructions by email
51 51 def send_unlock_instructions
52   - ::Devise::Mailer.unlock_instructions(self).deliver
  52 + ::Devise.mailer.unlock_instructions(self).deliver
53 53 end
54 54
55 55 # Resend the unlock instructions if the user is locked.
2  lib/devise/models/recoverable.rb
@@ -28,7 +28,7 @@ def reset_password!(new_password, new_password_confirmation)
28 28 # Resets reset password token and send reset password instructions by email
29 29 def send_reset_password_instructions
30 30 generate_reset_password_token!
31   - ::Devise::Mailer.reset_password_instructions(self).deliver
  31 + ::Devise.mailer.reset_password_instructions(self).deliver
32 32 end
33 33
34 34 protected
4 lib/generators/devise_install/templates/devise.rb
... ... @@ -1,9 +1,13 @@
1 1 # Use this hook to configure devise mailer, warden hooks and so forth. The first
2 2 # four configuration values can also be set straight in your models.
3 3 Devise.setup do |config|
  4 + # ==> Mailer Configuration
4 5 # Configure the e-mail address which will be shown in DeviseMailer.
5 6 config.mailer_sender = "please-change-me@config-initializers-devise.com"
6 7
  8 + # Configure the class responsible to send e-mails.
  9 + # config.mailer = "Devise::Mailer"
  10 +
7 11 # ==> ORM configuration
8 12 # Load and configure the ORM. Supports :active_record (default), :mongoid
9 13 # (bson_ext recommended) and :data_mapper (experimental).

0 comments on commit a2f8485

Please sign in to comment.
Something went wrong with that request. Please try again.