Link_to Show action in Rails

In my index.html.erb file, I have:

 <% @posts.each do |post| %> <%= post.title %> <%= link_to 'Show', post %> <% end %> 

How can I refer to the show action, but having <%= post.title => as the link name?

I tried <%= link_to '<%= post.title %>', post %> , but it does not work. Am I missing something or do I need to change something?

+4
source share
2 answers
 <%= link_to post.title, post %> 

Additional information: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-link_to

+6
source

this help will help:

  <%= link_to post.title, post_path(post) %>. 

You should also read the following: rail guides

0
source

All Articles