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

Changeset 3158

Show
Ignore:
Timestamp:
11/22/05 08:41:59 (3 years ago)
Author:
marcel
Message:

Apply [3157] to stable. Make ActionController's render honor the :locals option when rendering a :file. Closes #1665.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/stable/actionpack/CHANGELOG

    r3137 r3158  
    11*SVN* 
     2 
     3* Make ActionController's render honor the :locals option when rendering a :file. #1665. [Emanuel Borsboom, Marcel Molina Jr.] 
    24 
    35* Strip out trailing &_= for raw post bodies. Closes #2868. [Sam Stephenson] 
  • branches/stable/actionpack/lib/action_controller/base.rb

    r3016 r3158  
    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] 
     
    645649      end 
    646650 
    647       def render_file(template_path, status = nil, use_full_path = false
     651      def render_file(template_path, status = nil, use_full_path = false, locals = {}
    648652        add_variables_to_assigns 
    649653        assert_existance_of_template_file(template_path) if use_full_path 
    650654        logger.info("Rendering #{template_path}" + (status ? " (#{status})" : '')) if logger 
    651         render_text(@template.render_file(template_path, use_full_path), status) 
     655        render_text(@template.render_file(template_path, use_full_path, locals), status) 
    652656      end 
    653657 
  • branches/stable/actionpack/test/controller/new_render_test.rb

    r2777 r3158  
    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   
     
    243259  end 
    244260 
     261  def test_render_file_with_instance_variables 
     262    get :render_file_with_instance_variables 
     263    assert_equal "The secret is in the sauce\n", @response.body 
     264  end 
     265 
     266  def test_render_file_not_using_full_path 
     267    get :render_file_not_using_full_path  
     268    assert_equal "The secret is in the sauce\n", @response.body 
     269  end 
     270 
     271  def test_render_file_with_locals 
     272    get :render_file_with_locals 
     273    assert_equal "The secret is in the sauce\n", @response.body 
     274  end 
     275 
    245276  def test_attempt_to_access_object_method 
    246277    assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }