public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Make sure render :template works with :locals. [#524 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
timhaines (author)
Tue Jul 01 20:26:34 -0700 2008
lifo (committer)
Tue Jul 01 20:30:34 -0700 2008
commit  f5052dd8a39099e4930faafe9b01e63ced2f6391
tree    b822185ee19ee7cec9a0e7e8bccc81f4108bc6d5
parent  aff2d331720a3143914a0fffd1eba613dc333bfc
...
733
734
735
 
 
 
736
737
738
...
855
856
857
858
 
859
860
861
...
733
734
735
736
737
738
739
740
741
...
858
859
860
 
861
862
863
864
0
@@ -733,6 +733,9 @@ module ActionController #:nodoc:
0
       #   # Renders the template located in [TEMPLATE_ROOT]/weblog/show.r(html|xml) (in Rails, app/views/weblog/show.erb)
0
       #   render :template => "weblog/show"
0
       #
0
+      #   # Renders the template with a local variable
0
+      #   render :template => "weblog/show", :locals => {:customer => Customer.new}
0
+      #
0
       # === Rendering a file
0
       #
0
       # File rendering works just like action rendering except that it takes a filesystem path. By default, the path
0
@@ -855,7 +858,7 @@ module ActionController #:nodoc:
0
             render_for_file(file, options[:status], options[:use_full_path], options[:locals] || {})
0
 
0
           elsif template = options[:template]
0
-            render_for_file(template, options[:status], true)
0
+            render_for_file(template, options[:status], true, options[:locals] || {})
0
 
0
           elsif inline = options[:inline]
0
             add_variables_to_assigns
...
268
269
270
 
 
 
 
271
272
273
...
820
821
822
 
 
 
 
 
823
824
825
...
268
269
270
271
272
273
274
275
276
277
...
824
825
826
827
828
829
830
831
832
833
834
0
@@ -268,6 +268,10 @@ class NewRenderTestController < ActionController::Base
0
     render :template => "test/hello_world"
0
   end
0
 
0
+  def render_with_explicit_template_with_locals
0
+    render :template => "test/render_file_with_locals", :locals => { :secret => 'area51' }
0
+  end
0
+
0
   def double_render
0
     render :text => "hello"
0
     render :text => "world"
0
@@ -820,6 +824,11 @@ EOS
0
     assert_equal "world", assigns["hello"]
0
   end
0
 
0
+  def test_template_with_locals
0
+    get :render_with_explicit_template_with_locals
0
+    assert_equal "The secret is area51\n", @response.body
0
+  end
0
+
0
   def test_update_page
0
     get :update_page
0
     assert_template nil

Comments