Question

In my Rails 4 app, I have the following code that grabs all the books from the database and displays them, with the Show link last:

<% @books.each do |book| %>
      <tr>
        <td><%= book.title %></td>
        <td><%= book.author %></td>
        <td><%= book.owner %></td>
        <td><%= book.is_available %></td>
        <td><%= link_to 'Show', book %></td>

      </tr>
    <% end %>

But I don't want to have Show as a separate link. Instead, I want all the book titles to be linked to the book's Show page. I can't figure out how to do that.

It would make more sense to have the title link to the show rather than a separate show link. Hope this is clear. Thank you!

Était-ce utile?

La solution

<% @books.each do |book| %>
  <tr>
    <td><%= link_to book.title, book %></td>
    <td><%= book.author %></td>
    <td><%= book.owner %></td>
    <td><%= book.is_available %></td>
  </tr>
<% end %>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top