Skip to content

Commit

Permalink
Make ActionController#render(string) work as a shortcut for render :a…
Browse files Browse the repository at this point in the history
…ction => string. [#1435]

Examples:
  # Instead of render(:action => 'other_action')
  render('other_action')

Note : Argument must not have any '/'
  • Loading branch information
lifo committed Dec 25, 2008
1 parent d67e038 commit cd1d6e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
9 changes: 6 additions & 3 deletions actionpack/CHANGELOG
@@ -1,13 +1,16 @@
*2.3.0 [Edge]*

* Make ActionController#render(string) work as a shortcut for render :file/:template => string. [#1435] [Pratik Naik] Examples:
* Make ActionController#render(string) work as a shortcut for render :file/:template/:action => string. [#1435] [Pratik Naik] Examples:

# Instead of render(:file => '/Users/lifo/home.html.erb')
render('/Users/lifo/home.html.erb') # argument must begin with a '/'
# Instead of render(:action => 'other_action')
render('other_action') # argument has no '/'

# Instead of render(:template => 'controller/action')
render('controller/action') # argument must not begin with a '/', but contain a '/'

# Instead of render(:file => '/Users/lifo/home.html.erb')
render('/Users/lifo/home.html.erb') # argument must begin with a '/'

* Add :prompt option to date/time select helpers. #561 [Sam Oliver]

* Fixed that send_file shouldn't set an etag #1578 [Hongli Lai]
Expand Down
4 changes: 3 additions & 1 deletion actionpack/lib/action_controller/base.rb
Expand Up @@ -866,9 +866,11 @@ def render(options = nil, extra_options = {}, &block) #:doc:
elsif options == :update
options = extra_options.merge({ :update => true })
elsif options.is_a?(String)
case position = options.index('/')
case options.index('/')
when 0
extra_options[:file] = options
when nil
extra_options[:action] = options
else
extra_options[:template] = options
end
Expand Down
19 changes: 19 additions & 0 deletions actionpack/test/controller/render_test.rb
Expand Up @@ -81,6 +81,10 @@ def render_action_hello_world
render :action => "hello_world"
end

def render_action_hello_world_as_string
render "hello_world"
end

def render_action_hello_world_with_symbol
render :action => :hello_world
end
Expand Down Expand Up @@ -296,6 +300,10 @@ def layout_test_with_different_layout
render :action => "hello_world", :layout => "standard"
end

def layout_test_with_different_layout_and_string_action
render "hello_world", :layout => "standard"
end

def rendering_without_layout
render :action => "hello_world", :layout => false
end
Expand Down Expand Up @@ -743,6 +751,12 @@ def test_render_action
assert_template "test/hello_world"
end

def test_render_action_hello_world_as_string
get :render_action_hello_world_as_string
assert_equal "Hello world!", @response.body
assert_template "test/hello_world"
end

def test_render_action_with_symbol
get :render_action_hello_world_with_symbol
assert_template "test/hello_world"
Expand Down Expand Up @@ -1043,6 +1057,11 @@ def test_layout_test_with_different_layout
assert_equal "<html>Hello world!</html>", @response.body
end

def test_layout_test_with_different_layout
get :layout_test_with_different_layout_and_string_action
assert_equal "<html>Hello world!</html>", @response.body
end

def test_rendering_without_layout
get :rendering_without_layout
assert_equal "Hello world!", @response.body
Expand Down

0 comments on commit cd1d6e8

Please sign in to comment.