I implemented the official Creating the Blog Application project as per the directions given. But I am not getting the idea of link_to used in this project like:
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, :confirm => 'Are you sure?', :method => :delete %></td>
given in app/views/posts/index.html.erb file, also corresponding code in app/controllers/posts_controller.rb for rendering html pages in app/views/posts/ directory.
If I want to render a new html page say index2.html.erb in app/views/posts/ directory that does not have ‘Edit’ and ‘Destroy’ links compared to index.html.erb, then how should I write link_to and corresponding code in posts_controller.rb ?
If you want an action called
index2, say for a example URL likehttp://localhost:3000/posts/index2, then you need to:Create an action (method) for it in the
posts_controller.rb:Create a view file for it in the
app/viewsdirectory calledindex2.html.erbAdd a route to
config/routes.rb, for example:To link to the newly created
index2page, add a link in some otherhtml.erbfile to it like this:I highly recommend the book Agile Web Development with Rails (Pragmatic Programmers)