Hi I am new to rails and need some guidance. I am sure I am misunderstanding something obvious.
I would like the user name of the person who leaves a comment to show on the view page. I have a partial that goes through the collection of comments for the particular object for example a school. I can't figure out how to pass that user variable into the partial so that I can display the login name for the comment. My Comments model is polymorphic and I am pretty sure that is making this more complex.
Here are the models:
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic => true
has_many :comments, :through => :schools
class School < ActiveRecord::Base
belongs_to :installation
belongs_to :neighborhood
has_many :comments, :as => :commentable
class User < ActiveRecord::Base
has_many :users, :through => :schools
School's controller:
def show
@installation = Installation.find(params[:installation_id])
@school = School.find(params[:id])
@neighborhood = @school.neighborhood
@comment = @school.comments
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @school }
end
end
The comment partial:
<div class="box-one">
<img src="/images/comment_top.png" alt="" />
<div class="inside">
<p><span class="stars"><%= display_stars(comment.stars) %></span><br />
<%= comment.content %></p>
</div>
<img src="/images/comment_bottom.png" alt="" />
</div>
The school view:
<%= render :partial => "shared/comment", :collection => @comment %>