In that case, you set
the @lendable_here instance variable to the instance ID that??™s available. In this way, you save
two pieces of information in the same place: first, that this book can be lent from this library,
and which instance ID is available. If more than one instance is available, the last available
will get used. You also have a @returnable_here instance variable to say whether any book
instance is lent from this library.
CHAPTER 14 ?– THE LIBLIB RAILS APPLICATION 264
So, for the view you have the @book, @sorted, @lendable_here, and @returnable_here
instance variables to use for providing good information to both a Borrower and a Librarian.
You do that like this:
<%=@book.name%>
Authors:
<% for author in @book.authors %>
- <%= author %>
<% end %>
ISBN: <%= @book.isbn %>
Copies:
<% for id, instance in @sorted %>
At <%=instance[0]%>: <%= instance[1] %>
(<%= instance[2] %> available)<% end %>
<% if @a_librarian %>
<%= link_to 'Add instance', {:action => 'add_instance',
:id => params[:id]}, :post => true %> |
<%= link_to 'Remove instance', {:action => 'remove_instance',
:id => @lendable_here, :bookid => params[:id]},
:post => true if @lendable_here %>
<%= 'Remove instance' unless @lendable_here %> |
<%= link_to 'Remove this book', {:action => 'remove_description',
:id => params[:id] }, :post => true if @sorted.empty? %>
<%= 'Remove this book' unless @sorted.
Pages:
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393