aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/CHANGELOG2
-rwxr-xr-xactionpack/lib/action_controller/base.rb2
-rw-r--r--actionpack/lib/action_view/base.rb5
-rw-r--r--actionpack/lib/action_view/partials.rb2
-rw-r--r--actionpack/test/controller/new_render_test.rb9
-rw-r--r--actionpack/test/fixtures/test/_hash_object.rhtml1
6 files changed, 18 insertions, 3 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index f46b6fd700..b94f0e2f6e 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that render :partial would fail when :object was a Hash (due to backwards compatibility issues) #2148 [Sam Stephenson]
+
* Fixed JavascriptHelper#auto_complete_for to only include unique items #2153 [Thomas Fuchs]
* Fixed all AssetHelper methods to work with relative paths, such that javascript_include_tag('stdlib/standard') will look in /javascripts/stdlib/standard instead of '/stdlib/standard/' #1963
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index b9bab6229a..0c229fda8d 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -600,7 +600,7 @@ module ActionController #:nodoc:
if collection = options[:collection]
render_partial_collection(partial, collection, options[:spacer_template], options[:locals], options[:status])
else
- render_partial(partial, options[:object], options[:locals], options[:status])
+ render_partial(partial, ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals], options[:status])
end
elsif options[:nothing]
diff --git a/actionpack/lib/action_view/base.rb b/actionpack/lib/action_view/base.rb
index fbc9a66a05..cbaeedc0fe 100644
--- a/actionpack/lib/action_view/base.rb
+++ b/actionpack/lib/action_view/base.rb
@@ -137,6 +137,9 @@ module ActionView #:nodoc:
@@compiled_templates = CompiledTemplates.new
include @@compiled_templates
+ class ObjectWrapper < Struct.new(:value) #:nodoc:
+ end
+
def self.load_helpers(helper_dir)#:nodoc:
Dir.foreach(helper_dir) do |helper_file|
next unless helper_file =~ /_helper.rb$/
@@ -200,7 +203,7 @@ module ActionView #:nodoc:
elsif options[:partial] && options[:collection]
render_partial_collection(options[:partial], options[:collection], options[:spacer_template], options[:locals])
elsif options[:partial]
- render_partial(options[:partial], options[:object], options[:locals])
+ render_partial(options[:partial], ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals])
elsif options[:inline]
render_template(options[:type] || :rhtml, options[:inline], nil, options[:locals] || {})
end
diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb
index e1dcd4ee9d..5a129f12ab 100644
--- a/actionpack/lib/action_view/partials.rb
+++ b/actionpack/lib/action_view/partials.rb
@@ -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
+ local_assigns[partial_name.intern] ||= object.is_a?(ActionView::Base::ObjectWrapper) ? object.value : object
render("#{path}/_#{partial_name}", local_assigns)
end
diff --git a/actionpack/test/controller/new_render_test.rb b/actionpack/test/controller/new_render_test.rb
index 7c829e68de..a1af0a0091 100644
--- a/actionpack/test/controller/new_render_test.rb
+++ b/actionpack/test/controller/new_render_test.rb
@@ -101,6 +101,10 @@ class NewRenderTestController < ActionController::Base
def empty_partial_collection
render :partial => "customer", :collection => []
end
+
+ def partial_with_hash_object
+ render :partial => "hash_object", :object => {:first_name => "Sam"}
+ end
def hello_in_a_string
@customers = [ Customer.new("david"), Customer.new("mary") ]
@@ -371,6 +375,11 @@ class NewRenderTest < Test::Unit::TestCase
assert_equal " ", @response.body
end
+ def test_partial_with_hash_object
+ get :partial_with_hash_object
+ assert_equal "Sam", @response.body
+ end
+
def test_render_text_with_assigns
get :render_text_with_assigns
assert_equal "world", assigns["hello"]
diff --git a/actionpack/test/fixtures/test/_hash_object.rhtml b/actionpack/test/fixtures/test/_hash_object.rhtml
new file mode 100644
index 0000000000..037a7368d6
--- /dev/null
+++ b/actionpack/test/fixtures/test/_hash_object.rhtml
@@ -0,0 +1 @@
+<%= hash_object[:first_name] %> \ No newline at end of file