提交 80307c8b 编写于 作者: P Pratik Naik

Make ActionController#render(symbol) behave same as ActionController#render(string) [#1435]

上级 cd1d6e87
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
# Instead of render(:action => 'other_action') # Instead of render(:action => 'other_action')
render('other_action') # argument has no '/' render('other_action') # argument has no '/'
render(:other_action)
# Instead of render(:template => 'controller/action') # Instead of render(:template => 'controller/action')
render('controller/action') # argument must not begin with a '/', but contain a '/' render('controller/action') # argument must not begin with a '/', but contain a '/'
......
...@@ -859,14 +859,14 @@ def append_view_path(path) ...@@ -859,14 +859,14 @@ def append_view_path(path)
def render(options = nil, extra_options = {}, &block) #:doc: def render(options = nil, extra_options = {}, &block) #:doc:
raise DoubleRenderError, "Can only render or redirect once per action" if performed? raise DoubleRenderError, "Can only render or redirect once per action" if performed?
validate_render_arguments(options, extra_options) validate_render_arguments(options, extra_options, block_given?)
if options.nil? if options.nil?
return render(:file => default_template, :layout => true) return render(:file => default_template, :layout => true)
elsif options == :update elsif options == :update
options = extra_options.merge({ :update => true }) options = extra_options.merge({ :update => true })
elsif options.is_a?(String) elsif options.is_a?(String) || options.is_a?(Symbol)
case options.index('/') case options.to_s.index('/')
when 0 when 0
extra_options[:file] = options extra_options[:file] = options
when nil when nil
...@@ -1193,8 +1193,8 @@ def render_for_text(text = nil, status = nil, append_response = false) #:nodoc: ...@@ -1193,8 +1193,8 @@ def render_for_text(text = nil, status = nil, append_response = false) #:nodoc:
end end
end end
def validate_render_arguments(options, extra_options) def validate_render_arguments(options, extra_options, has_block)
if options && options != :update && !options.is_a?(String) && !options.is_a?(Hash) if options && (has_block && options != :update) && !options.is_a?(String) && !options.is_a?(Hash) && !options.is_a?(Symbol)
raise RenderError, "You called render with invalid options : #{options.inspect}" raise RenderError, "You called render with invalid options : #{options.inspect}"
end end
......
...@@ -304,6 +304,10 @@ def layout_test_with_different_layout_and_string_action ...@@ -304,6 +304,10 @@ def layout_test_with_different_layout_and_string_action
render "hello_world", :layout => "standard" render "hello_world", :layout => "standard"
end end
def layout_test_with_different_layout_and_symbol_action
render :hello_world, :layout => "standard"
end
def rendering_without_layout def rendering_without_layout
render :action => "hello_world", :layout => false render :action => "hello_world", :layout => false
end end
...@@ -1057,11 +1061,16 @@ def test_layout_test_with_different_layout ...@@ -1057,11 +1061,16 @@ def test_layout_test_with_different_layout
assert_equal "<html>Hello world!</html>", @response.body assert_equal "<html>Hello world!</html>", @response.body
end end
def test_layout_test_with_different_layout def test_layout_test_with_different_layout_and_string_action
get :layout_test_with_different_layout_and_string_action get :layout_test_with_different_layout_and_string_action
assert_equal "<html>Hello world!</html>", @response.body assert_equal "<html>Hello world!</html>", @response.body
end end
def test_layout_test_with_different_layout_and_symbol_action
get :layout_test_with_different_layout_and_symbol_action
assert_equal "<html>Hello world!</html>", @response.body
end
def test_rendering_without_layout def test_rendering_without_layout
get :rendering_without_layout get :rendering_without_layout
assert_equal "Hello world!", @response.body assert_equal "Hello world!", @response.body
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册