Skip to content

Commit

Permalink
Refactor subject with i18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
José Valim and Mikel Lindsaar committed Jan 23, 2010
1 parent ddfc072 commit 5c3ef8c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions actionmailer/lib/action_mailer/base.rb
Expand Up @@ -398,8 +398,7 @@ def mail(headers = {})
m = @message m = @message


# Get default subject from I18n if none is set # Get default subject from I18n if none is set
headers[:subject] ||= I18n.t(:subject, :scope => [:actionmailer, mailer_name, action_name], headers[:subject] ||= default_subject
:default => action_name.humanize)


# Give preference to headers and fallbacks to the ones set in mail # Give preference to headers and fallbacks to the ones set in mail
content_type = headers[:content_type] || m.content_type content_type = headers[:content_type] || m.content_type
Expand All @@ -418,7 +417,7 @@ def mail(headers = {})
# Do something # Do something
else else
# TODO Ensure that we don't need to pass I18n.locale as detail # TODO Ensure that we don't need to pass I18n.locale as detail
templates = self.class.template_root.find_all(action_name, {}, mailer_name) templates = self.class.template_root.find_all(action_name, {}, self.class.mailer_name)


if templates.size == 1 && !m.has_attachments? if templates.size == 1 && !m.has_attachments?
content_type ||= templates[0].mime_type.to_s content_type ||= templates[0].mime_type.to_s
Expand Down Expand Up @@ -449,6 +448,11 @@ def mail(headers = {})
m m
end end


def default_subject
mailer_scope = self.class.mailer_name.gsub('/', '.')
I18n.t(:subject, :scope => [:actionmailer, mailer_scope, action_name], :default => action_name.humanize)
end

def insert_part(container, template, charset) def insert_part(container, template, charset)
part = Mail::Part.new part = Mail::Part.new
part.content_type = template.mime_type.to_s part.content_type = template.mime_type.to_s
Expand Down

0 comments on commit 5c3ef8c

Please sign in to comment.