Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 link_to the show action but having the <%= post.title => as the name of the link?

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

like image 505
user1919937 Avatar asked Dec 20 '12 20:12

user1919937


2 Answers

<%= link_to post.title, post %>

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

like image 136
regulatethis Avatar answered Sep 20 '22 22:09

regulatethis


this wil help:

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

Also you should read this: rails guides

like image 22
dan1d Avatar answered Sep 21 '22 22:09

dan1d