Skip to content
Browse files

render :partial recognizes Active Record associations as Arrays. Closes

#8538.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6920 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent b05fc40 commit a6a1dc967cb65ac3f842d15f89eef7e32f7547cf @jeremy jeremy committed Jun 1, 2007
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* render :partial recognizes Active Record associations as Arrays. #8538 [kamal]
+
* Routing: drop semicolon and comma as route separators. [Jeremy Kemper]
* request.remote_ip understands X-Forwarded-For addresses with nonstandard whitespace. #7386 [moses]
View
2 actionpack/lib/action_view/partials.rb
@@ -64,7 +64,7 @@ def render_partial(partial_path, local_assigns = nil, deprecated_local_assigns =
else
render("#{path}/_#{partial_name}", local_assigns)
end
- when Array
+ when Array, ActiveRecord::Associations::AssociationCollection
if partial_path.any?
path = ActionController::RecordIdentifier.partial_path(partial_path.first)
collection = partial_path
View
64 actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -0,0 +1,64 @@
+require File.dirname(__FILE__) + '/../active_record_unit'
+
+class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
+ fixtures :developers, :projects, :developers_projects, :topics, :replies
+
+ class RenderPartialWithRecordIdentificationController < ActionController::Base
+ def render_with_has_many_and_belongs_to_association
+ @developer = Developer.find(1)
+ render :partial => @developer.projects
+ end
+
+ def render_with_has_many_association
+ @topic = Topic.find(1)
+ render :partial => @topic.replies
+ end
+
+ def render_with_belongs_to_association
+ @reply = Reply.find(1)
+ render :partial => @reply.topic
+ end
+
+ def render_with_record
+ @developer = Developer.find(:first)
+ render :partial => @developer
+ end
+
+ def render_with_record_collection
+ @developers = Developer.find(:all)
+ render :partial => @developers
+ end
+ end
+
+ def setup
+ @controller = RenderPartialWithRecordIdentificationController.new
+ @request = ActionController::TestRequest.new
+ @response = ActionController::TestResponse.new
+ super
+ end
+
+ def test_rendering_partial_with_has_many_and_belongs_to_association
+ get :render_with_has_many_and_belongs_to_association
+ assert_template 'projects/_project'
+ end
+
+ def test_rendering_partial_with_has_many_association
+ get :render_with_has_many_association
+ assert_template 'replies/_reply'
+ end
+
+ def test_rendering_partial_with_belongs_to_association
+ get :render_with_belongs_to_association
+ assert_template 'topics/_topic'
+ end
+
+ def test_render_with_record
+ get :render_with_record
+ assert_template 'developers/_developer'
+ end
+
+ def test_render_with_record_collection
+ get :render_with_record_collection
+ assert_template 'developers/_developer'
+ end
+end
View
2 actionpack/test/fixtures/topic.rb
@@ -1,3 +1,3 @@
class Topic < ActiveRecord::Base
- has_many :replies, :include => [:user], :dependent => :destroy
+ has_many :replies, :dependent => :destroy
end

0 comments on commit a6a1dc9

Please sign in to comment.
Something went wrong with that request. Please try again.