Permalink
Browse files

Fixed that render :partial would fail when :object was a Hash (due to…

… backwards compatibility issues) #2148 [Sam Stephenson]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2160 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 46110aa commit e3c02d8c66ae3df7a58ba7d76dfc464f26dcff67 @dhh dhh committed Sep 9, 2005
View
@@ -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
@@ -600,7 +600,7 @@ def render(options = nil, deprecated_status = nil) #:doc:
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]
@@ -137,6 +137,9 @@ class Base
@@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 @@ def render(options = {}, old_local_assigns = {})
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
@@ -52,7 +52,7 @@ def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns =
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
@@ -101,6 +101,10 @@ def partial_collection_with_locals
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 @@ def test_empty_partial_collection
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"]
@@ -0,0 +1 @@
+<%= hash_object[:first_name] %>

0 comments on commit e3c02d8

Please sign in to comment.