John Mossel
2009-Jul-21 23:53 UTC
Render a partial that has assosciations with something else
hi, Does anyone know how I can render a partial that has an assosciation with something else (e.g. render a comments partial in posts-- where the comments belong to posts). Thanks -- Posted via http://www.ruby-forum.com/.
Zach Karpinski
2009-Jul-22 04:05 UTC
Re: Render a partial that has assosciations with something else
If you have your model associations setup properly you should be able to access them using post.comments For example: class Post < ActiveRecord::Base has_many :comments end class Comment < ActiveRecord::Base belongs_to :post end In _post.rhtml you can do <%= render :partial => "comment/comment", :collection => post.comments %> That assumes you have a partial called _comment.rhtml in the "comment" directory under views. On Jul 21, 6:53 pm, John Mossel <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> hi, > Does anyone know how I can render a partial that has an assosciation > with something else (e.g. render a comments partial in posts-- where the > comments belong to posts). > Thanks > -- > Posted viahttp://www.ruby-forum.com/.