Go ahead with the newly generated file called
app/views/store/index.rhtml, and change into some welcoming message, such as this:
Welcome
Hi and welcome to the Shoplet Online Store
75
C H A P T E R 5
This store is built with JRuby on Rails and is the
first project application for the book Practical JRuby on Rails.
Here you can look at various products and order them at very fine prices.
You can try this file by pointing your browser at http://localhost:3000/store. Now,
because you need to be able to browse products, you??™ll need to change the products action in
the store controller. Open app/controllers/store_controller.rb and change the empty
products method into this code:
def products
@products = Product.find(:all)
end
Now you also need to change the view to show the products, so once again go to the view
directory and open app/views/store/products.rhtml:
Products
<% for product in @products %>
<%= link_to h(product.name), :action => 'product', :id => product %> |
<%=price product %> |
<%= button_to "Add to cart", :action => 'add_to_cart', :id => product%> |
<% end %>
You can try it out by visiting http://localhost:3000/store/products. You might notice
that you create a button in this code that points to the action add_to_cart. That??™s something
you haven??™t created yet, but you want that later on.
Pages:
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153