Reputation: 11
<h2>Hello World</h2>
<% @posts.each do |post| %>
<h2><%= link_to post.title, @post %></h2>
<p><%= post.content %></p>
<hr />
<% end %>
When i do this it will let me view the page with no errors and have a hyper link on all my post titles but now its not redirecting me to the page with just the post i wanted... Still trying to figure this error on my part i guess, out.
Upvotes: 0
Views: 709
Reputation: 16629
It should be
<% @posts.each do |post| %>
<h2><%= link_to post.title, post %></h2>
<p><%= post.content %></p>
<hr />
<% end %>
Note that I changed @post -> post
, because inside the loop you need to get the path for each post
object.
So then you don't need to do @post = Post.find(params[:id])
, as you said.
Upvotes: 1
Reputation: 863
Unless you have modified post path somehow:
<%= link_to 'post.title', post_path(post) %>
Upvotes: 1