Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix rendering partials at the top level [#795 state:resolved]

  • Loading branch information...
commit 3b9324e62f770f1a0a457f7ad5fe6a3287ecae1f 1 parent 04248c6
Joshua Peek josh authored
2  actionpack/lib/action_view/partials.rb
View
@@ -146,7 +146,7 @@ def render_partial_collection(partial_path, collection, partial_spacer_template
def find_partial_path(partial_path)
if partial_path.include?('/')
- "#{File.dirname(partial_path)}/_#{File.basename(partial_path)}"
+ File.join(File.dirname(partial_path), "_#{File.basename(partial_path)}")
elsif respond_to?(:controller)
"#{controller.class.controller_path}/_#{partial_path}"
else
1  actionpack/test/fixtures/_top_level_partial.html.erb
View
@@ -0,0 +1 @@
+top level partial html
1  actionpack/test/fixtures/_top_level_partial_only.erb
View
@@ -0,0 +1 @@
+top level partial
18 actionpack/test/template/render_test.rb
View
@@ -19,6 +19,10 @@ def test_render_file_without_specific_extension
assert_equal "Hello world!", @view.render("test/hello_world")
end
+ def test_render_file_at_top_level
+ assert_equal 'Elastica', @view.render('/shared')
+ end
+
def test_render_file_with_full_path
template_path = File.join(File.dirname(__FILE__), '../fixtures/test/hello_world.erb')
assert_equal "Hello world!", @view.render(:file => template_path)
@@ -47,6 +51,20 @@ def test_render_partial
assert_equal "only partial", @view.render(:partial => "test/partial_only")
end
+ def test_render_partial_with_format
+ assert_equal 'partial html', @view.render(:partial => 'test/partial')
+ end
+
+ def test_render_partial_at_top_level
+ # file fixtures/_top_level_partial_only.erb (not fixtures/test)
+ assert_equal 'top level partial', @view.render(:partial => '/top_level_partial_only')
+ end
+
+ def test_render_partial_with_format_at_top_level
+ # file fixtures/_top_level_partial.html.erb (not fixtures/test, with format extension)
+ assert_equal 'top level partial html', @view.render(:partial => '/top_level_partial')
+ end
+
def test_render_partial_with_locals
assert_equal "5", @view.render(:partial => "test/counter", :locals => { :counter_counter => 5 })
end
Please sign in to comment.
Something went wrong with that request. Please try again.