diff options
author | Rick Olson <technoweenie@gmail.com> | 2007-07-01 00:04:03 +0000 |
---|---|---|
committer | Rick Olson <technoweenie@gmail.com> | 2007-07-01 00:04:03 +0000 |
commit | a450e769f1c7f5c68799f570856d020863528d17 (patch) | |
tree | 9a92e903be548ecb9728e4c26a0c29d9cd70c3c4 | |
parent | d0ff4ec1936b6888ce199ef5131c3a2d866a968c (diff) | |
download | rails-a450e769f1c7f5c68799f570856d020863528d17.tar.gz rails-a450e769f1c7f5c68799f570856d020863528d17.tar.bz2 rails-a450e769f1c7f5c68799f570856d020863528d17.zip |
Allow you to render views with periods in the name. Closes #8076 [norbert]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7158 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r-- | actionpack/CHANGELOG | 4 | ||||
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 14 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 9 |
3 files changed, 23 insertions, 4 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index c5953703a7..917303797f 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Allow you to render views with periods in the name. Closes #8076 [norbert] + + render :partial => 'show.html.erb' + * Improve capture helper documentation. #8796 [kampers] * Prefix nested resource named routes with their action name, e.g. new_group_user_path(@group) instead of group_new_user_path(@group). The old nested action named route is deprecated in Rails 1.2.4. #8558 [David Chelimsky] diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 06e69bcccf..9da33d2ac8 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -110,12 +110,17 @@ module ActionView end def partial_counter_name(partial_name) - "#{partial_name.split('/').last}_counter".intern + "#{partial_variable_name(partial_name)}_counter".intern + end + + def partial_variable_name(partial_name) + partial_name.split('/').last.split('.').first.intern end def extracting_object(partial_name, local_assigns, deprecated_local_assigns) + variable_name = partial_variable_name(partial_name) if local_assigns.is_a?(Hash) || local_assigns.nil? - controller.instance_variable_get("@#{partial_name}") + controller.instance_variable_get("@#{variable_name}") else # deprecated form where object could be passed in as second parameter local_assigns @@ -132,12 +137,13 @@ module ActionView end def add_object_to_local_assigns!(partial_name, local_assigns, object) - local_assigns[partial_name.intern] ||= + variable_name = partial_variable_name(partial_name) + local_assigns[variable_name] ||= if object.is_a?(ActionView::Base::ObjectWrapper) object.value else object - end || controller.instance_variable_get("@#{partial_name}") + end || controller.instance_variable_get("@#{variable_name}") end end end diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 8b4149dcb4..553022e3d9 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -135,6 +135,10 @@ class TestController < ActionController::Base def partial render :partial => 'partial' end + + def partial_dot_html + render :partial => 'partial.html.erb' + end def partial_as_rjs render :update do |page| @@ -393,6 +397,11 @@ class RenderTest < Test::Unit::TestCase assert_equal 'partial html', @response.body end + def test_should_render_html_partial_with_dot + get :partial_dot_html + assert_equal 'partial html', @response.body + end + def test_should_render_html_formatted_partial_with_rjs xhr :get, :partial_as_rjs assert_equal %(Element.replace("foo", "partial html");), @response.body |