From ed911caaa4b565208888401a217260e0f96bd3db Mon Sep 17 00:00:00 2001 From: Scott Windsor Date: Mon, 14 Sep 2009 12:14:41 -0700 Subject: [PATCH] Adding layout accessor to override any default or base class layout. --- actionmailer/lib/action_mailer/base.rb | 5 +++++ actionmailer/test/mail_layout_test.rb | 6 ++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 84997de..8fa9d35 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -354,6 +354,10 @@ module ActionMailer #:nodoc: # have multiple mailer methods share the same template. adv_attr_accessor :template + # Specify the layout to use for the current message. This overrides any + # default layout or action mailer layout. + adv_attr_accessor :layout + # Override the mailer name, which defaults to an inflected version of the # mailer's class name. If you want to use a template in a non-standard # location, you can use this to specify that location. @@ -560,6 +564,7 @@ module ActionMailer #:nodoc: if opts[:file] && (opts[:file] !~ /\// && !opts[:file].respond_to?(:render)) opts[:file] = "#{mailer_name}/#{opts[:file]}" end + opts[:layout] = self.layout unless self.layout.nil? begin old_template, @template = @template, initialize_template_class(body) diff --git a/actionmailer/test/mail_layout_test.rb b/actionmailer/test/mail_layout_test.rb index 50901f5..619ed77 100644 --- a/actionmailer/test/mail_layout_test.rb +++ b/actionmailer/test/mail_layout_test.rb @@ -11,14 +11,16 @@ class AutoLayoutMailer < ActionMailer::Base recipients recipient subject "You have a mail" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :layout => 'spam', :body => { :world => "Earth" }) + layout "spam" + body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" }) end def nolayout(recipient) recipients recipient subject "You have a mail" from "tester@example.com" - body render(:inline => "Hello, <%= @world %>", :layout => false, :body => { :world => "Earth" }) + layout false + body render(:inline => "Hello, <%= @world %>", :body => { :world => "Earth" }) end def multipart(recipient, type = nil) -- 1.6.0.4