From 069da86f12a21322538308244070f034bbf3866f Mon Sep 17 00:00:00 2001 From: Tim Haines Date: Tue, 1 Jul 2008 23:52:57 +1200 Subject: [PATCH] render template with locals --- actionpack/lib/action_controller/base.rb | 5 ++++- actionpack/test/controller/new_render_test.rb | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 7cc6702..a7b2f14 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -733,6 +733,9 @@ module ActionController #:nodoc: # # 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 @@ -855,7 +858,7 @@ module ActionController #:nodoc: 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 diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb index deda47f..a5384f2 100644 --- a/actionpack/test/controller/new_render_test.rb +++ b/actionpack/test/controller/new_render_test.rb @@ -267,6 +267,10 @@ class NewRenderTestController < ActionController::Base def render_with_explicit_template render :template => "test/hello_world" end + + def render_with_explicit_template_with_locals + render :template => "test/customer", :locals => { :customer => Customer.new("david") } + end def double_render render :text => "hello" @@ -819,6 +823,11 @@ EOS 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 "Hello: david", @response.body + end def test_update_page get :update_page -- 1.5.6.1