Without the comments, the new file should look like this:
ActionController::Routing::Routes.draw do |map|
map.connect '', :controller => "store"
map.connect ':controller/service.wsdl', :action => 'wsdl'
map.connect ':controller/:action/:id'
end
What you say is just that an empty path should go to the store controller. So, go ahead
and restart the web server right now! I??™m waiting . . .
Good! One thing is left before you can browse around easily. You need that helper I mentioned
before, called plural. Open app/helpers/application_helper.rb and add this code
together with the rest:
def plural(name)
h Inflector.pluralize(name)
end
As you see, you just use the Inflector. However, you hide it within a helper, because that??™s
nice if you want to use it in other places.
It??™s now time for you to try out the application again. Just visit http://localhost:3000,
and see the new menu that gives you access to fun product browsing. You??™re now about
halfway finished. The next part is to add a shopping cart and allow the customer to check that
out.
Adding a Shopping Cart
As mentioned before, the current application might be fun to play with, but there??™s still no way
to buy anything, so the shop isn??™t likely to generate revenue. You??™ll help the situation by adding
CHAPTER 5 ?– A DATABASE-DRIVEN SHOP 79
a cart. The first thing you have to do is decide how to implement this. I??™ll take a simple
approach here. Because in your application the contents of the cart can be represented with
a product ID and a number for quantity, you??™ll be able to save an array of these two numbers
in the session and re-create the products and the price information from this array.
Pages:
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158