1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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
This commit is contained in:
David Heinemeier Hansson 2005-09-09 07:27:44 +00:00
parent 46110aa689
commit e3c02d8c66
6 changed files with 18 additions and 3 deletions

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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

View file

@ -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"]

View file

@ -0,0 +1 @@
<%= hash_object[:first_name] %>