aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_view/base.rb1
-rw-r--r--actionpack/lib/action_view/partials.rb27
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