I know this is a really simple question, but I’ve gone completely blank! I’m reading through the Rails guides and looking at the getting started section. The following code is displaying all comments that belong to the current Post:
<h2>Comments</h2>
<% @post.comments.each do |comment| %>
<p>
<b>Commenter:</b>
<%= comment.commenter %>
</p>
<p>
<b>Comment:</b>
<%= comment.body %>
</p>
<% end %>
What is the simplest way of linking to each individual comment? For reference the page I am looking at is http://guides.rubyonrails.org/getting_started.html
The models are as follows:
class Post < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
Rails will try to create route helpers to assist you in this. You can get a full list by running
rake routes, but there are good odds that the one you’ll be looking for is namedcomment_path:For reference, check out the Rails Routing Guide.