I have a table for doing CRUD operations on books, and also users can check in books (the checking out is done my a different controller)
At the moment the check in works for the book table, but I can't update user data - the integer of how many books they have loaned out
Here is part of my table:
<tr><% @books.each do |book| %>
<td><%= book.title %></td>
<td><%= book.author %></td>
<td class ="onloan"><%= book.onloan %></td>
<td><%= link_to 'show', book %> </td>
<td><%= link_to 'edit', edit_book_path(book) %></td>
<td><%= link_to 'Destroy', book, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<td><%= link_to 'Check in', check_in_path(book)%></td>
</tr>
<% end %>
What I want to add is something like
@user = User.find(params[:id])
@user.books_on_loan - 1
Here is the check in def of my controller:
def check_in
Book.find(params[:id]).update_attribute(:onloan, 0)
redirect_to root_path
end
Aucun commentaire:
Enregistrer un commentaire