user1919937
user1919937

Reputation: 447

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?

Upvotes: 5

Views: 12098

Answers (2)

dan1d
dan1d

Reputation: 151

this wil help:

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

Also you should read this: rails guides

Upvotes: 1

regulatethis
regulatethis

Reputation: 2362

<%= link_to post.title, post %>

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

Upvotes: 8

Related Questions