Module: Devise::Mailers::Helpers
- Extended by:
- ActiveSupport::Concern
- Included in:
- Devise::Mailer
- Defined in:
- lib/devise/mailers/helpers.rb
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
protected
Returns the value of attribute resource.
-
#scope_name ⇒ Object
readonly
protected
Returns the value of attribute scope_name.
Instance Method Summary collapse
-
#devise_mail(record, action, opts = {}, &block) ⇒ Object
protected
Configure default email options.
- #devise_mapping ⇒ Object protected
- #headers_for(action, opts) ⇒ Object protected
- #initialize_from_record(record) ⇒ Object protected
- #mailer_sender(mapping) ⇒ Object protected
-
#subject_for(key) ⇒ Object
protected
Set up a subject doing an I18n lookup.
- #template_paths ⇒ Object protected
Instance Attribute Details
#resource ⇒ Object (readonly, protected)
Returns the value of attribute resource.
14 15 16 |
# File 'lib/devise/mailers/helpers.rb', line 14 def resource @resource end |
#scope_name ⇒ Object (readonly, protected)
Returns the value of attribute scope_name.
14 15 16 |
# File 'lib/devise/mailers/helpers.rb', line 14 def scope_name @scope_name end |
Instance Method Details
#devise_mail(record, action, opts = {}, &block) ⇒ Object (protected)
Configure default email options
17 18 19 20 |
# File 'lib/devise/mailers/helpers.rb', line 17 def devise_mail(record, action, opts = {}, &block) initialize_from_record(record) mail headers_for(action, opts), &block end |
#devise_mapping ⇒ Object (protected)
27 28 29 |
# File 'lib/devise/mailers/helpers.rb', line 27 def devise_mapping @devise_mapping ||= Devise.mappings[scope_name] end |
#headers_for(action, opts) ⇒ Object (protected)
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/devise/mailers/helpers.rb', line 31 def headers_for(action, opts) headers = { subject: subject_for(action), to: resource.email, from: mailer_sender(devise_mapping), reply_to: mailer_sender(devise_mapping), template_path: template_paths, template_name: action } # Give priority to the mailer's default if they exists. headers.delete(:from) if default_params[:from] headers.delete(:reply_to) if default_params[:reply_to] headers.merge!(opts) @email = headers[:to] headers end |
#initialize_from_record(record) ⇒ Object (protected)
22 23 24 25 |
# File 'lib/devise/mailers/helpers.rb', line 22 def initialize_from_record(record) @scope_name = Devise::Mapping.find_scope!(record) @resource = instance_variable_set("@#{devise_mapping.name}", record) end |
#mailer_sender(mapping) ⇒ Object (protected)
50 51 52 53 54 55 56 |
# File 'lib/devise/mailers/helpers.rb', line 50 def mailer_sender(mapping) if Devise.mailer_sender.is_a?(Proc) Devise.mailer_sender.call(mapping.name) else Devise.mailer_sender end end |
#subject_for(key) ⇒ Object (protected)
Set up a subject doing an I18n lookup. At first, it attempts to set a subject based on the current mapping:
en:
devise:
mailer:
confirmation_instructions:
user_subject: '...'
If one does not exist, it fallbacks to ActionMailer default:
en:
devise:
mailer:
confirmation_instructions:
subject: '...'
81 82 83 84 |
# File 'lib/devise/mailers/helpers.rb', line 81 def subject_for(key) I18n.t(:"#{devise_mapping.name}_subject", scope: [:devise, :mailer, key], default: [:subject, key.to_s.humanize]) end |
#template_paths ⇒ Object (protected)
58 59 60 61 62 |
# File 'lib/devise/mailers/helpers.rb', line 58 def template_paths template_path = _prefixes.dup template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views? template_path end |