SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 379 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

Further, if the @results instance variable
exists, you know that you should view search results. The actual results are displayed using a
partial called book_result. Finally, you also add a link to make it possible to add a new book
description if you??™re a Librarian.
The book_result partial is simple. You don??™t use tables for this display, so the only things
you need are the title, authors, and a link to more information (see Listing 14-4).
Listing 14-4. app/views/book/_book_result.rhtml
p><%=link_to book_result.name,
:action => :book, :id=>book_result.id%>
by
<%= book_result.authors.join(", ") %> (<%=book_result.isbn%>)


Because you know that each entry in the list of results will be a BookDescription struct
(which you created in the last chapter), you can just ask it for name, ID, authors, and ISBN and
display the information. The link points to the book action, which displays one specific book
with some more data and options available.
Before we look at the book action and view, let??™s briefly see what the add_description
button does (in book_controller.rb):
def add_description
redirect_to :controller => 'amazon'
end
CHAPTER 14 ?–  THE LIBLIB RAILS APPLICATION 263
Because adding a new book requires you to import it from Amazon.com, this action just
redirects the Librarian to the AmazonController.
Viewing a book is a tad complicated, for the simple reason that you need to collate the
instance information into something useful for the viewer.


Pages:
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391