diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-16 16:06:29 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-04-16 16:06:29 +0000 |
commit | 82456d9392e4abc0a402294c32089b646975eed4 (patch) | |
tree | b03c117a022c8e8a04833509e74fb17b95b5b38e /actionpack | |
parent | 0baf3444579a3fac780b58471db00045a9ac7cc5 (diff) | |
download | rails-82456d9392e4abc0a402294c32089b646975eed4.tar.gz rails-82456d9392e4abc0a402294c32089b646975eed4.tar.bz2 rails-82456d9392e4abc0a402294c32089b646975eed4.zip |
Fixed partials handling
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_view/base.rb | 1 | ||||
-rw-r--r-- | actionpack/lib/action_view/partials.rb | 27 |
2 files changed, 24 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb index e3b0821225..2c906b90ba 100644 --- a/actionpack/lib/action_view/base.rb +++ b/actionpack/lib/action_view/base.rb @@ -264,6 +264,7 @@ module ActionView #:nodoc: def evaluate_locals(local_assigns = {}) b = binding + local_assigns.stringify_keys! local_assigns.each { |key, value| eval "#{key} = local_assigns[\"#{key}\"]", b } @assigns.each { |key, value| instance_variable_set "@#{key}", value } xml = Builder::XmlMarkup.new(:indent => 2) diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index 2251bd321c..cfe53858b4 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -31,11 +31,12 @@ module ActionView # # This will render the partial "advertisement/_ad.rhtml" regardless of which controller this is being called from. module Partials - def render_partial(partial_path, object = nil, local_assigns = {}) + def render_partial(partial_path, local_assigns = {}, deprecated_local_assigns = {}) path, partial_name = partial_pieces(partial_path) - object ||= controller.instance_variable_get("@#{partial_name}") - counter_name = partial_counter_name(partial_name) - local_assigns = local_assigns.merge(counter_name => 1) unless local_assigns.has_key?(counter_name) + object = extracting_object(partial_name, local_assigns, deprecated_local_assigns) + local_assigns = extract_local_assigns(local_assigns, deprecated_local_assigns) + add_counter_to_local_assigns!(partial_name, local_assigns) + render("#{path}/_#{partial_name}", { partial_name => object }.merge(local_assigns)) end @@ -69,5 +70,23 @@ module ActionView def partial_counter_name(partial_name) "#{partial_name.split('/').last}_counter" end + + def extracting_object(partial_name, local_assigns, deprecated_local_assigns) + if local_assigns.is_a?(Hash) || local_assigns.nil? + controller.instance_variable_get("@#{partial_name}") + else + # deprecated form where object could be passed in as second parameter + local_assigns + end + end + + def extract_local_assigns(local_assigns, deprecated_local_assigns) + local_assigns.is_a?(Hash) ? local_assigns : deprecated_local_assigns + end + + def add_counter_to_local_assigns!(partial_name, local_assigns) + counter_name = partial_counter_name(partial_name) + local_assigns[counter_name] = 1 unless local_assigns.has_key?(counter_name) + end end end |