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 :file => 
string. [#1435]

Examples:
  # Instead of render(:file => '/Users/lifo/home.html.erb')
  render('/Users/lifo/home.html.erb')

Note : Filename must begin with a forward slash ('/')
lifo (author)
Thu Dec 25 13:27:56 -0800 2008
commit  061952392afd1dae1aa97a816e9a0c79df7c4514
tree    ce5599e69468632d5898ddb5088f0d729e4ddc91
parent  dd0753458f2a16c876c52734f84a242f56746607
...
1
2
 
 
 
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1,5 +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
+
0
+  # Instead of render(:file => '/Users/lifo/home.html.erb')
0
+  render('/Users/lifo/home.html.erb')
0
+
0
+  Note : Filename must begin with a forward slash ('/')
0
+
0
 * Add :prompt option to date/time select helpers. #561 [Sam Oliver]
0
 
0
 * Fixed that send_file shouldn't set an etag #1578 [Hongli Lai]
...
865
866
867
 
 
 
 
 
 
 
868
869
870
...
1183
1184
1185
1186
 
1187
1188
1189
...
865
866
867
868
869
870
871
872
873
874
875
876
877
...
1190
1191
1192
 
1193
1194
1195
1196
0
@@ -865,6 +865,13 @@ module ActionController #:nodoc:
0
           return render(:file => default_template, :layout => true)
0
         elsif options == :update
0
           options = extra_options.merge({ :update => true })
0
+        elsif options.is_a?(String)
0
+          case options.index('/')
0
+          when 0
0
+            extra_options[:file] = options
0
+          end
0
+
0
+          options = extra_options
0
         end
0
 
0
         layout = pick_layout(options)
0
@@ -1183,7 +1190,7 @@ module ActionController #:nodoc:
0
       end
0
 
0
       def validate_render_arguments(options, extra_options)
0
-        if options && options != :update && !options.is_a?(Hash)
0
+        if options && options != :update && !options.is_a?(String) && !options.is_a?(Hash)
0
           raise RenderError, "You called render with invalid options : #{options.inspect}"
0
         end
0
 
...
104
105
106
 
 
 
 
 
 
107
108
109
...
124
125
126
 
 
 
 
 
127
128
129
...
182
183
184
185
186
187
188
189
190
191
...
751
752
753
 
 
 
 
 
754
755
756
...
766
767
768
 
 
 
 
 
769
770
771
...
831
832
833
834
835
836
837
838
839
840
...
104
105
106
107
108
109
110
111
112
113
114
115
...
130
131
132
133
134
135
136
137
138
139
140
...
193
194
195
 
 
 
 
196
197
198
...
758
759
760
761
762
763
764
765
766
767
768
...
778
779
780
781
782
783
784
785
786
787
788
...
848
849
850
 
 
 
 
851
852
853
0
@@ -104,6 +104,12 @@ class TestController < ActionController::Base
0
     render :file => path
0
   end
0
 
0
+  def render_file_as_string_with_instance_variables
0
+    @secret = 'in the sauce'
0
+    path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_ivar.erb'))
0
+    render path
0
+  end
0
+
0
   def render_file_not_using_full_path
0
     @secret = 'in the sauce'
0
     render :file => 'test/render_file_with_ivar'
0
@@ -124,6 +130,11 @@ class TestController < ActionController::Base
0
     render :file => path, :locals => {:secret => 'in the sauce'}
0
   end
0
 
0
+  def render_file_as_string_with_locals
0
+    path = File.expand_path(File.join(File.dirname(__FILE__), '../fixtures/test/render_file_with_locals.erb'))
0
+    render path, :locals => {:secret => 'in the sauce'}
0
+  end
0
+
0
   def accessing_request_in_template
0
     render :inline =>  "Hello: <%= request.host %>"
0
   end
0
@@ -182,10 +193,6 @@ class TestController < ActionController::Base
0
     render :text => "appended"
0
   end
0
 
0
-  def render_invalid_args
0
-    render("test/hello")
0
-  end
0
-
0
   def render_vanilla_js_hello
0
     render :js => "alert('hello')"
0
   end
0
@@ -751,6 +758,11 @@ class RenderTest < ActionController::TestCase
0
     assert_equal "The secret is in the sauce\n", @response.body
0
   end
0
 
0
+  def test_render_file_as_string_with_instance_variables
0
+    get :render_file_as_string_with_instance_variables
0
+    assert_equal "The secret is in the sauce\n", @response.body
0
+  end
0
+
0
   def test_render_file_not_using_full_path
0
     get :render_file_not_using_full_path
0
     assert_equal "The secret is in the sauce\n", @response.body
0
@@ -766,6 +778,11 @@ class RenderTest < ActionController::TestCase
0
     assert_equal "The secret is in the sauce\n", @response.body
0
   end
0
 
0
+  def test_render_file_as_string_with_locals
0
+    get :render_file_as_string_with_locals
0
+    assert_equal "The secret is in the sauce\n", @response.body
0
+  end
0
+
0
   def test_render_file_from_template
0
     get :render_file_from_template
0
     assert_equal "The secret is in the sauce\n", @response.body
0
@@ -831,10 +848,6 @@ class RenderTest < ActionController::TestCase
0
     assert_equal 'appended', @response.body
0
   end
0
 
0
-  def test_attempt_to_render_with_invalid_arguments
0
-    assert_raises(ActionController::RenderError) { get :render_invalid_args }
0
-  end
0
-
0
   def test_attempt_to_access_object_method
0
     assert_raises(ActionController::UnknownAction, "No action responded to [clone]") { get :clone }
0
   end

Comments

shingara Fri Dec 26 00:46:04 -0800 2008

A better exemple of using this news it’s for me :

render(Rails.root(’/public/404.html’))