Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Make ActionController#render(symbol) behave same as ActionController#…

…render(string) [#1435]
  • Loading branch information...
commit 80307c8b0a889acc7abb7f4e52fd4c02e1063ba8 1 parent cd1d6e8
Pratik lifo authored
1  actionpack/CHANGELOG
@@ -4,6 +4,7 @@
4 4
5 5 # Instead of render(:action => 'other_action')
6 6 render('other_action') # argument has no '/'
  7 + render(:other_action)
7 8
8 9 # Instead of render(:template => 'controller/action')
9 10 render('controller/action') # argument must not begin with a '/', but contain a '/'
10 actionpack/lib/action_controller/base.rb
@@ -859,14 +859,14 @@ def append_view_path(path)
859 859 def render(options = nil, extra_options = {}, &block) #:doc:
860 860 raise DoubleRenderError, "Can only render or redirect once per action" if performed?
861 861
862   - validate_render_arguments(options, extra_options)
  862 + validate_render_arguments(options, extra_options, block_given?)
863 863
864 864 if options.nil?
865 865 return render(:file => default_template, :layout => true)
866 866 elsif options == :update
867 867 options = extra_options.merge({ :update => true })
868   - elsif options.is_a?(String)
869   - case options.index('/')
  868 + elsif options.is_a?(String) || options.is_a?(Symbol)
  869 + case options.to_s.index('/')
870 870 when 0
871 871 extra_options[:file] = options
872 872 when nil
@@ -1193,8 +1193,8 @@ def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
1193 1193 end
1194 1194 end
1195 1195
1196   - def validate_render_arguments(options, extra_options)
1197   - if options && options != :update && !options.is_a?(String) && !options.is_a?(Hash)
  1196 + def validate_render_arguments(options, extra_options, has_block)
  1197 + if options && (has_block && options != :update) && !options.is_a?(String) && !options.is_a?(Hash) && !options.is_a?(Symbol)
1198 1198 raise RenderError, "You called render with invalid options : #{options.inspect}"
1199 1199 end
1200 1200
11 actionpack/test/controller/render_test.rb
@@ -304,6 +304,10 @@ def layout_test_with_different_layout_and_string_action
304 304 render "hello_world", :layout => "standard"
305 305 end
306 306
  307 + def layout_test_with_different_layout_and_symbol_action
  308 + render :hello_world, :layout => "standard"
  309 + end
  310 +
307 311 def rendering_without_layout
308 312 render :action => "hello_world", :layout => false
309 313 end
@@ -1057,11 +1061,16 @@ def test_layout_test_with_different_layout
1057 1061 assert_equal "<html>Hello world!</html>", @response.body
1058 1062 end
1059 1063
1060   - def test_layout_test_with_different_layout
  1064 + def test_layout_test_with_different_layout_and_string_action
1061 1065 get :layout_test_with_different_layout_and_string_action
1062 1066 assert_equal "<html>Hello world!</html>", @response.body
1063 1067 end
1064 1068
  1069 + def test_layout_test_with_different_layout_and_symbol_action
  1070 + get :layout_test_with_different_layout_and_symbol_action
  1071 + assert_equal "<html>Hello world!</html>", @response.body
  1072 + end
  1073 +
1065 1074 def test_rendering_without_layout
1066 1075 get :rendering_without_layout
1067 1076 assert_equal "Hello world!", @response.body

0 comments on commit 80307c8

Please sign in to comment.
Something went wrong with that request. Please try again.