Render a partial that has assosciations with something else

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).

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

class Comment < ActiveRecord::Base
belongs_to :post

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 M. [email protected]


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs