method
create!
v2.1.0 -
Show latest stable
- Class:
ActionMailer::Base
create!(method_name, *parameters)public
Initialize the mailer via the given method_name. The body will be rendered and a new TMail::Mail object created.
# File actionmailer/lib/action_mailer/base.rb, line 444
def create!(method_name, *parameters) #:nodoc:
initialize_defaults(method_name)
__send__(method_name, *parameters)
# If an explicit, textual body has not been set, we check assumptions.
unless String === @body
# First, we look to see if there are any likely templates that match,
# which include the content-type in their file name (i.e.,
# "the_template_file.text.html.erb", etc.). Only do this if parts
# have not already been specified manually.
if @parts.empty?
templates = Dir.glob("#{template_path}/#{@template}.*")
templates.each do |path|
basename = File.basename(path)
template_regex = Regexp.new("^([^\\\.]+)\\\.([^\\\.]+\\\.[^\\\.]+)\\\.(" + template_extensions.join('|') + ")$")
next unless md = template_regex.match(basename)
template_name = basename
content_type = md.captures[1].gsub('.', '/')
@parts << Part.new(:content_type => content_type,
:disposition => "inline", :charset => charset,
:body => render_message(template_name, @body))
end
unless @parts.empty?
@content_type = "multipart/alternative"
@parts = sort_parts(@parts, @implicit_parts_order)
end
end
# Then, if there were such templates, we check to see if we ought to
# also render a "normal" template (without the content type). If a
# normal template exists (or if there were no implicit parts) we render
# it.
template_exists = @parts.empty?
template_exists ||= Dir.glob("#{template_path}/#{@template}.*").any? { |i| File.basename(i).split(".").length == 2 }
@body = render_message(@template, @body) if template_exists
# Finally, if there are other message parts and a textual body exists,
# we shift it onto the front of the parts and set the body to nil (so
# that create_mail doesn't try to render it in addition to the parts).
if [email protected]? && String === @body
@parts.unshift Part.new(:charset => charset, :body => @body)
@body = nil
end
end
# If this is a multipart e-mail add the mime_version if it is not
# already set.
@mime_version ||= "1.0" if [email protected]?
# build the mail object itself
@mail = create_mail
end Related methods
- Instance methods
- controller_name
- controller_path
- create!
- deliver!
- mailer_name
- mailer_name=
- Class methods
- deliver
- mailer_name
- method_missing
- new
- receive
- register_template_extension
- template_root=
- Private methods
-
create_mail -
initialize_defaults -
initialize_template_class -
perform_delivery_sendmail -
perform_delivery_smtp -
perform_delivery_test -
render -
render_message -
sort_parts -
template_path