Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8212

Show
Ignore:
Timestamp:
11/26/07 03:36:28 (1 year ago)
Author:
rick
Message:

Update ActionMailer so it treats ActionView the same way that ActionController does. Closes #10244 [rick]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionmailer/CHANGELOG

    r8166 r8212  
    11*SVN* 
     2 
     3* Update ActionMailer so it treats ActionView the same way that ActionController does.  Closes #10244 [rick] 
     4 
     5  * Pass the template_root as an array as ActionView's view_path 
     6  * Request templates with the "#{mailer_name}/#{action}" as opposed to just "#{action}" 
    27 
    38* Fixed that partials would be broken when using text.plain.erb as the extension #10130 [java] 
  • trunk/actionmailer/lib/action_mailer/base.rb

    r8111 r8212  
    299299    adv_attr_accessor :implicit_parts_order 
    300300     
    301     # Override the mailer name, which defaults to an inflected version of the 
    302     # mailer's class name. If you want to use a template in a non-standard 
    303     # location, you can use this to specify that location. 
    304     adv_attr_accessor :mailer_name 
    305      
    306301    # Defaults to "1.0", but may be explicitly given if needed. 
    307302    adv_attr_accessor :mime_version 
     
    323318    adv_attr_accessor :template 
    324319 
     320    # Override the mailer name, which defaults to an inflected version of the 
     321    # mailer's class name. If you want to use a template in a non-standard 
     322    # location, you can use this to specify that location. 
     323    def mailer_name(value = nil) 
     324      if value 
     325        self.mailer_name = value 
     326      else 
     327        self.class.mailer_name 
     328      end 
     329    end 
     330     
     331    def mailer_name=(value) 
     332      self.class.mailer_name = value 
     333    end 
     334 
    325335    # The mail object instance referenced by this mailer. 
    326336    attr_reader :mail 
    327337 
    328338    class << self 
     339      attr_writer :mailer_name 
     340 
     341      def mailer_name 
     342        @mailer_name ||= name.underscore 
     343      end 
     344 
     345      # for ActionView compatibility 
     346      alias_method :controller_name, :mailer_name 
     347      alias_method :controller_path, :mailer_name 
     348 
    329349      def method_missing(method_symbol, *parameters)#:nodoc: 
    330350        case method_symbol.id2name 
     
    477497      def render(opts) 
    478498        body = opts.delete(:body) 
     499        if opts[:file] && opts[:file] !~ /\// 
     500          opts[:file] = "#{mailer_name}/#{opts[:file]}" 
     501        end 
    479502        initialize_template_class(body).render(opts) 
    480503      end 
     
    485508 
    486509      def initialize_template_class(assigns) 
    487         ActionView::Base.new(template_path, assigns, self) 
     510        ActionView::Base.new([template_root], assigns, self) 
    488511      end 
    489512 
  • trunk/actionmailer/test/fixtures/test_mailer/included_subtemplate.text.plain.erb

    r8188 r8212  
    1 Hey Ho, <%= render "subtemplate" %> 
     1Hey Ho, <%= render :partial => "subtemplate" %> 
  • trunk/actionmailer/test/mail_render_test.rb

    r8166 r8212  
    2626    subject    "Including another template in the one being rendered" 
    2727    from       "tester@example.com" 
     28  end 
     29   
     30  def included_old_subtemplate(recipient) 
     31    recipients recipient 
     32    subject    "Including another template in the one being rendered" 
     33    from       "tester@example.com" 
     34    body       render(:inline => "Hello, <%= render \"subtemplate\" %>", :body => { :world => "Earth" }) 
    2835  end 
    2936 
     
    8289    assert_equal "Hey Ho, let's go!", mail.body.strip 
    8390  end 
     91   
     92  def test_deprecated_old_subtemplate 
     93    assert_raises ActionView::ActionViewError do 
     94      RenderMailer.deliver_included_old_subtemplate(@recipient) 
     95    end 
     96  end 
    8497end 
    8598