mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed that an instance variable with the same name as a partial should be implicitly passed as the partial :object. Closes #2269.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2522 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
e3655ef733
commit
0886bb391d
3 changed files with 18 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
*SVN*
|
||||
|
||||
* Fixed that an instance variable with the same name as a partial should be implicitly passed as the partial :object #2269 [court3nay]
|
||||
|
||||
* Update Prototype to V1.4.0_pre11, script.aculo.us to [2502] [Thomas Fuchs]
|
||||
|
||||
* Make assert_tag :children count appropriately. Closes #2181. [jamie@bravenet.com]
|
||||
|
|
|
@ -52,7 +52,7 @@ module ActionView
|
|||
local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns)
|
||||
local_assigns = local_assigns ? local_assigns.clone : {}
|
||||
add_counter_to_local_assigns!(partial_name, local_assigns)
|
||||
local_assigns[partial_name.intern] ||= object.is_a?(ActionView::Base::ObjectWrapper) ? object.value : object
|
||||
add_object_to_local_assigns!(partial_name, local_assigns, object)
|
||||
|
||||
ActionController::Base.benchmark("Rendered #{path}/_#{partial_name}", Logger::DEBUG, false) do
|
||||
render("#{path}/_#{partial_name}", local_assigns)
|
||||
|
@ -111,5 +111,10 @@ module ActionView
|
|||
counter_name = partial_counter_name(partial_name)
|
||||
local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name)
|
||||
end
|
||||
|
||||
def add_object_to_local_assigns!(partial_name, local_assigns, object)
|
||||
local_assigns[partial_name.intern] ||= object.is_a?(ActionView::Base::ObjectWrapper) ? object.value : object
|
||||
local_assigns[partial_name.intern] ||= controller.instance_variable_get("@#{partial_name}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -106,6 +106,11 @@ class NewRenderTestController < ActionController::Base
|
|||
render :partial => "hash_object", :object => {:first_name => "Sam"}
|
||||
end
|
||||
|
||||
def partial_with_implicit_local_assignment
|
||||
@customer = Customer.new("Marcel")
|
||||
render :partial => "customer"
|
||||
end
|
||||
|
||||
def hello_in_a_string
|
||||
@customers = [ Customer.new("david"), Customer.new("mary") ]
|
||||
render :text => "How's there? #{render_to_string("test/list")}"
|
||||
|
@ -380,6 +385,11 @@ class NewRenderTest < Test::Unit::TestCase
|
|||
assert_equal "Sam", @response.body
|
||||
end
|
||||
|
||||
def test_partial_with_implicit_local_assignment
|
||||
get :partial_with_implicit_local_assignment
|
||||
assert_equal "Hello: Marcel", @response.body
|
||||
end
|
||||
|
||||
def test_render_text_with_assigns
|
||||
get :render_text_with_assigns
|
||||
assert_equal "world", assigns["hello"]
|
||||
|
|
Loading…
Reference in a new issue