diff options
Diffstat (limited to 'actionmailer/lib/action_mailer/base.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/base.rb | 43 |
1 files changed, 38 insertions, 5 deletions
diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index c1cce73303..e0a99fa00c 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -23,8 +23,7 @@ module ActionMailer #:nodoc: # bcc ["bcc@example.com", "Order Watcher <watcher@example.com>"] # from "system@example.com" # subject "New account information" - # - # @account = recipient + # body :account => recipient # end # end # @@ -36,7 +35,7 @@ module ActionMailer #:nodoc: # * <tt>cc</tt> - Takes one or more email addresses. These addresses will receive a carbon copy of your email. Sets the <tt>Cc:</tt> header. # * <tt>bcc</tt> - Takes one or more email addresses. These addresses will receive a blind carbon copy of your email. Sets the <tt>Bcc:</tt> header. # * <tt>reply_to</tt> - Takes one or more email addresses. These addresses will be listed as the default recipients when replying to your email. Sets the <tt>Reply-To:</tt> header. - # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header wil be set by the delivery agent. + # * <tt>sent_on</tt> - The date on which the message was sent. If not set, the header will be set by the delivery agent. # * <tt>content_type</tt> - Specify the content type of the message. Defaults to <tt>text/plain</tt>. # * <tt>headers</tt> - Specify additional headers to be set for the message, e.g. <tt>headers 'X-Mail-Count' => 107370</tt>. # @@ -144,12 +143,13 @@ module ActionMailer #:nodoc: # subject "New account information" # from "system@example.com" # content_type "multipart/alternative" + # body :account => recipient # # part :content_type => "text/html", - # :body => render_message("signup-as-html", :account => recipient) + # :data => render_message("signup-as-html") # # part "text/plain" do |p| - # p.body = render_message("signup-as-plain", :account => recipient) + # p.body = render_message("signup-as-plain") # p.content_transfer_encoding = "base64" # end # end @@ -492,11 +492,13 @@ module ActionMailer #:nodoc: # body, headers, etc.) can be set on it. def part(params) params = {:content_type => params} if String === params + if custom_headers = params.delete(:headers) ActiveSupport::Deprecation.warn('Passing custom headers with :headers => {} is deprecated. ' << 'Please just pass in custom headers directly.', caller[0,10]) params.merge!(custom_headers) end + part = Mail::Part.new(params) yield part if block_given? @parts << part @@ -514,6 +516,20 @@ module ActionMailer #:nodoc: part(params, &block) end + # Allow you to set assigns for your template: + # + # body :greetings => "Hi" + # + # Will make @greetings available in the template to be rendered. + def body(object=nil) + returning(super) do # Run deprecation hooks + if object.is_a?(Hash) + @assigns_set = true + object.each { |k, v| instance_variable_set(:"@#{k}", v) } + end + end + end + # Instantiate a new mailer object. If +method_name+ is not +nil+, the mailer # will be initialized according to the named method. If not, the mailer will # remain uninitialized (useful when you only need to invoke the "receive" @@ -549,6 +565,23 @@ module ActionMailer #:nodoc: private + # Render a message but does not set it as mail body. Useful for rendering + # data for part and attachments. + # + # Examples: + # + # render_message "special_message" + # render_message :template => "special_message" + # render_message :inline => "<%= 'Hi!' %>" + def render_message(object) + case object + when String + render_to_body(:template => object) + else + render_to_body(object) + end + end + # Set up the default values for the various instance variables of this # mailer. Subclasses may override this method to provide different # defaults. |