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

Changeset 3157

Show
Ignore:
Timestamp:
11/22/05 08:37:04 (3 years ago)
Author:
sam
Message:

Make ActionController's render honor the :locals option when rendering a :file. Closes #1665.

Files:

Legend:

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

    r3154 r3157  
    11*SVN* 
     2 
     3* Make ActionController's render honor the :locals option when rendering a :file. #1665. [Emanuel Borsboom, Marcel Molina Jr.] 
    24 
    35* Allow assert_tag(:conditions) to match the empty string when a tag has no children. Closes #2959. [Jamis Buck] 
  • trunk/actionpack/lib/action_controller/base.rb

    r3084 r3157  
    460460      end 
    461461 
     462      def session_enabled? 
     463        request.session_options[:disabled] != false 
     464      end 
     465 
    462466    protected 
    463467      # Renders the content that will be returned to the browser as the response body. 
     
    597601        else 
    598602          if file = options[:file] 
    599             render_file(file, options[:status], options[:use_full_path]
     603            render_file(file, options[:status], options[:use_full_path], options[:locals] || {}
    600604 
    601605          elsif template = options[:template] 
     
    646650      end 
    647651 
    648       def render_file(template_path, status = nil, use_full_path = false
     652      def render_file(template_path, status = nil, use_full_path = false, locals = {}
    649653        add_variables_to_assigns 
    650654        assert_existance_of_template_file(template_path) if use_full_path 
    651655        logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger 
    652         render_text(@template.render_file(template_path, use_full_path), status) 
     656        render_text(@template.render_file(template_path, use_full_path, locals), status) 
    653657      end 
    654658 
  • trunk/actionpack/test/controller/new_render_test.rb

    r3084 r3157  
    4343  def render_custom_code 
    4444    render :text => "hello world", :status => "404 Moved" 
     45  end 
     46 
     47  def render_file_with_instance_variables 
     48    @secret = 'in the sauce' 
     49    path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.rhtml') 
     50    render :file => path 
     51  end 
     52 
     53  def render_file_with_locals 
     54    path = File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.rhtml') 
     55    render :file => path, :locals => {:secret => 'in the sauce'}  
     56  end 
     57 
     58  def render_file_not_using_full_path 
     59    @secret = 'in the sauce' 
     60    render :file => 'test/render_file_with_ivar', :use_full_path => true 
    4561  end 
    4662   
     
    258274  end 
    259275 
     276  def test_render_file_with_instance_variables 
     277    get :render_file_with_instance_variables 
     278    assert_equal "The secret is in the sauce\n", @response.body 
     279  end 
     280 
     281  def test_render_file_not_using_full_path 
     282    get :render_file_not_using_full_path  
     283    assert_equal "The secret is in the sauce\n", @response.body 
     284  end 
     285 
     286  def test_render_file_with_locals 
     287    get :render_file_with_locals 
     288    assert_equal "The secret is in the sauce\n", @response.body 
     289  end 
     290 
    260291  def test_attempt_to_access_object_method 
    261292    assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }