I am new to rails so sorry for the simple question. I have followed several tutorials and set up a blog with comments (even using a little AJAX - Ha proud of myself). I have done some customizing and right now I am trying to display in the index.html.erb a comment count that is a clickable link that takes to you the show.html.erb page. Here is what I did so far and not sure it is right. In the comments_controller I have added the following:
def count
@post = Post.find(params[:post_id])
@comment = @post.comments.count(params[:comment])
end
First question is this the correct def to count comments associated with a particular post. Second question is how do I then call it in my index.html.erb page where I have the following:
<% @posts.each do |post| %>
<%= render :partial => post %>
<%= link_to 'View & Add Comments', post %>
<% end %>
As you can see I am currently using a link_to reference to get to the page but ideally would like it to show something like: Comments (8).