Skip to content

Commit

Permalink
Make sure render :template works with :locals. [#524 state:resolved]
Browse files Browse the repository at this point in the history
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
timhaines authored and lifo committed Jul 2, 2008
1 parent 25ce688 commit 6303ba0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/base.rb
Expand Up @@ -743,6 +743,9 @@ def append_view_path(path)
# # Renders the template located in [TEMPLATE_ROOT]/weblog/show.r(html|xml) (in Rails, app/views/weblog/show.erb)
# render :template => "weblog/show"
#
# # Renders the template with a local variable
# render :template => "weblog/show", :locals => {:customer => Customer.new}
#
# === Rendering a file
#
# File rendering works just like action rendering except that it takes a filesystem path. By default, the path
Expand Down Expand Up @@ -865,7 +868,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
render_for_file(file, options[:status], options[:use_full_path], options[:locals] || {})

elsif template = options[:template]
render_for_file(template, options[:status], true)
render_for_file(template, options[:status], true, options[:locals] || {})

elsif inline = options[:inline]
add_variables_to_assigns
Expand Down
11 changes: 10 additions & 1 deletion actionpack/test/controller/new_render_test.rb
Expand Up @@ -264,6 +264,10 @@ def render_with_explicit_template
render :template => "test/hello_world"
end

def render_with_explicit_template_with_locals
render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
end

def double_render
render :text => "hello"
render :text => "world"
Expand Down Expand Up @@ -810,7 +814,12 @@ def test_render_text_with_assigns
get :render_text_with_assigns
assert_equal "world", assigns["hello"]
end


def test_template_with_locals
get :render_with_explicit_template_with_locals
assert_equal "The secret is area51\n", @response.body
end

def test_update_page
get :update_page
assert_template nil
Expand Down

0 comments on commit 6303ba0

Please sign in to comment.