public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Make ActionController#render(string) work as a shortcut for render :template => 
string. [#1435]

Examples:
  # Instead of render(:template => 'controller/action')
  render('controller/action')

Note : Argument must not begin with a '/', but have at least one '/'
lifo (author)
Thu Dec 25 14:11:06 -0800 2008
commit  d67e03871eabb912434dafac3eeb8e6ea7c5585f
tree    ac7d7092f56c5e5bfe6c690d44bbf5c91fca8c24
parent  061952392afd1dae1aa97a816e9a0c79df7c4514
...
1
2
3
 
4
5
6
 
7
8
 
 
9
10
11
...
1
2
 
3
4
5
 
6
7
 
8
9
10
11
12
0
@@ -1,11 +1,12 @@
0
 *2.3.0 [Edge]*
0
 
0
-* Make ActionController#render(string) work as a shortcut for render :file => string. [#1435] [Pratik Naik] Examples:
0
+* Make ActionController#render(string) work as a shortcut for render :file/:template => string. [#1435] [Pratik Naik] Examples:
0
 
0
   # Instead of render(:file => '/Users/lifo/home.html.erb')
0
-  render('/Users/lifo/home.html.erb')
0
+  render('/Users/lifo/home.html.erb') # argument must begin with a '/'
0
 
0
-  Note : Filename must begin with a forward slash ('/')
0
+  # Instead of render(:template => 'controller/action')
0
+  render('controller/action') # argument must not begin with a '/', but contain a '/'
0
 
0
 * Add :prompt option to date/time select helpers. #561 [Sam Oliver]
0
 
...
866
867
868
869
 
870
871
 
 
872
873
874
...
866
867
868
 
869
870
871
872
873
874
875
876
0
@@ -866,9 +866,11 @@ module ActionController #:nodoc:
0
         elsif options == :update
0
           options = extra_options.merge({ :update => true })
0
         elsif options.is_a?(String)
0
-          case options.index('/')
0
+          case position = options.index('/')
0
           when 0
0
             extra_options[:file] = options
0
+          else
0
+            extra_options[:template] = options
0
           end
0
 
0
           options = extra_options
...
202
203
204
 
 
 
 
 
205
206
207
...
332
333
334
 
 
 
 
335
336
337
...
654
655
656
 
657
658
659
...
888
889
890
 
 
 
 
 
 
891
892
893
...
1073
1074
1075
 
 
 
 
 
1076
1077
1078
...
202
203
204
205
206
207
208
209
210
211
212
...
337
338
339
340
341
342
343
344
345
346
...
663
664
665
666
667
668
669
...
898
899
900
901
902
903
904
905
906
907
908
909
...
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
0
@@ -202,6 +202,11 @@ class TestController < ActionController::Base
0
     render :template => "test/hello"
0
   end
0
 
0
+  def render_xml_hello_as_string_template
0
+    @name = "David"
0
+    render "test/hello"
0
+  end
0
+
0
   def render_xml_with_custom_content_type
0
     render :xml => "<blah/>", :content_type => "application/atomsvc+xml"
0
   end
0
@@ -332,6 +337,10 @@ class TestController < ActionController::Base
0
     render :template => "test/hello_world"
0
   end
0
 
0
+  def render_with_explicit_string_template
0
+    render "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
@@ -654,6 +663,7 @@ class TestController < ActionController::Base
0
              "accessing_params_in_template",
0
              "accessing_params_in_template_with_layout",
0
              "render_with_explicit_template",
0
+             "render_with_explicit_string_template",
0
              "render_js_with_explicit_template",
0
              "render_js_with_explicit_action_template",
0
              "delete_with_js", "update_page", "update_page_with_instance_variables"
0
@@ -888,6 +898,12 @@ class RenderTest < ActionController::TestCase
0
     assert_equal "application/xml", @response.content_type
0
   end
0
 
0
+  def test_render_xml_as_string_template
0
+    get :render_xml_hello_as_string_template
0
+    assert_equal "<html>\n  <p>Hello David</p>\n<p>This is grand!</p>\n</html>\n", @response.body
0
+    assert_equal "application/xml", @response.content_type
0
+  end
0
+
0
   def test_render_xml_with_default
0
     get :greeting
0
     assert_equal "<p>This is grand!</p>\n", @response.body
0
@@ -1073,6 +1089,11 @@ class RenderTest < ActionController::TestCase
0
     assert_response :success
0
   end
0
 
0
+  def test_render_with_explicit_string_template
0
+    get :render_with_explicit_string_template
0
+    assert_equal "<html>Hello world!</html>", @response.body
0
+  end
0
+
0
   def test_double_render
0
     assert_raises(ActionController::DoubleRenderError) { get :double_render }
0
   end

Comments