Module: Devise::Mailers::Helpers
- Extended by:
- ActiveSupport::Concern
- Included in:
- Devise::Mailer
- Defined in:
- lib/devise/mailers/helpers.rb
Instance Method Summary collapse
-
#devise_mail(record, action, opts = {}) ⇒ Object
protected
Configure default email options.
- #devise_mapping ⇒ Object protected
- #headers_for(action, opts) ⇒ Object protected
- #initialize_from_record(record) ⇒ Object protected
- #mailer_from(mapping) ⇒ Object protected
- #mailer_reply_to(mapping) ⇒ Object protected
- #mailer_sender(mapping, sender = :from) ⇒ Object protected
-
#subject_for(key) ⇒ Object
protected
Setup a subject doing an I18n lookup.
- #template_paths ⇒ Object protected
Instance Method Details
#devise_mail(record, action, opts = {}) ⇒ Object (protected)
Configure default email options
14 15 16 17 |
# File 'lib/devise/mailers/helpers.rb', line 14 def devise_mail(record, action, opts={}) initialize_from_record(record) mail headers_for(action, opts) end |
#devise_mapping ⇒ Object (protected)
24 25 26 |
# File 'lib/devise/mailers/helpers.rb', line 24 def devise_mapping @devise_mapping ||= Devise.mappings[scope_name] end |
#headers_for(action, opts) ⇒ Object (protected)
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/devise/mailers/helpers.rb', line 28 def headers_for(action, opts) headers = { :subject => subject_for(action), :to => resource.email, :from => mailer_sender(devise_mapping), :reply_to => mailer_reply_to(devise_mapping), :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 @email = headers[:to] headers end |
#initialize_from_record(record) ⇒ Object (protected)
19 20 21 22 |
# File 'lib/devise/mailers/helpers.rb', line 19 def initialize_from_record(record) @scope_name = Devise::Mapping.find_scope!(record) @resource = instance_variable_set("@#{devise_mapping.name}", record) end |
#mailer_from(mapping) ⇒ Object (protected)
52 53 54 |
# File 'lib/devise/mailers/helpers.rb', line 52 def mailer_from(mapping) mailer_sender(mapping, :from) end |
#mailer_reply_to(mapping) ⇒ Object (protected)
48 49 50 |
# File 'lib/devise/mailers/helpers.rb', line 48 def mailer_reply_to(mapping) mailer_sender(mapping, :reply_to) end |
#mailer_sender(mapping, sender = :from) ⇒ Object (protected)
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/devise/mailers/helpers.rb', line 56 def mailer_sender(mapping, sender = :from) default_sender = default_params[sender] if default_sender.present? default_sender.respond_to?(:to_proc) ? instance_eval(&default_sender) : default_sender elsif Devise.mailer_sender.is_a?(Proc) Devise.mailer_sender.call(mapping.name) else Devise.mailer_sender end end |
#subject_for(key) ⇒ Object (protected)
Setup 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: '...'
90 91 92 93 |
# File 'lib/devise/mailers/helpers.rb', line 90 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)
67 68 69 70 71 |
# File 'lib/devise/mailers/helpers.rb', line 67 def template_paths template_path = _prefixes.dup template_path.unshift "#{@devise_mapping.scoped_path}/mailer" if self.class.scoped_views? template_path end |