Search code examples
ruby-on-railsruby-on-rails-4routeslink-to

link_to post edit view in rails


Really basic question about link_to that I'm having trouble finding a straight answer to.

So I have an index view that simply lists posts according to user email address.

<% @post.each do |post| %>
  <tr>
    <td class="email"><%= link_to post.user.email, post %></td>
  </tr>
<% end %>

As it stands, this links to the show view for the given post. How might I make it link to the edit view instead?


Solution

  • Pretty simple:

    <%= link_to post.user.email, edit_post_path(post) %>