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 142 | Next

Ola Bini

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

Also notice that you use the h helper to
avoid strange characters in the product name on the fifth line, and the price helper to format
the product price correctly on the eighth line.
If you try to visit one of the products at the moment it will show a page with Rails??™ standard
view message for views that you haven??™t changed yet. So, the next step is to open
store_controller.rb once again and add a single line to the product method:
def product
@product = Product.find(params[:id])
end
That takes care of finding the correct product. What??™s left is to display it in a pleasing way.
This is accomplished in the file app/views/store/product.rhtml. It should look like this:

<%= h @product.name %>


Description

<%= h @product.description %>


CHAPTER 5 ?–  A DATABASE-DRIVEN SHOP 76




Price    
  <%=price @product%>


<%= button_to "Add to cart",
:action => 'add_to_cart', :id => @product%>


Nothing fancy. You display the product name, description, and price, and follow that with
a button that lets the customer add it to the nonexistent cart.
Right now there are some glaring deficiencies in the application. First, it doesn??™t look so
usable. You need a menu or something. Second, when browsing products it would be helpful
if you didn??™t get to see all of them at the same time. Maybe you should only display products
within one product type at a time. Third, it looks abysmal at the moment.


Pages:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154