문제

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!

도움이 되었습니까?

해결책

<% @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 %>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top