views:

29

answers:

1

I have a "cart" model, a users cart id is stored in their session.

My routes look like this

map.resources :carts
map.cart "cart", :controller => "carts", :action => "show"

in my show view, i displayed the contents of the cart, and everything was fine. Then i decided i wanted the user to be able to update the quantity of items from the show view, so i added this to the view..

<% form_for @cart do |cart_form| %>
<% end %>

and now i get the following error

undefined method `to_sym' for nil:NilClass

on

<% form_for @cart do |cart_form| %>

Interestingly if i remove

map.cart "cart", :controller => "carts", :action => "show"

from my routes, and specify a cart id in the url, it works, but i do not want to be passing cart ids in the url.

Any idea how to fix this please?

[update]

rake routes looks like this:

carts GET    /carts(.:format)                               {:controller=>"carts", :action=>"index"}
POST   /carts(.:format)                               {:controller=>"carts", :action=>"create"}
new_cart GET    /carts/new(.:format)                           {:controller=>"carts", :action=>"new"}
edit_cart GET    /carts/:id/edit(.:format)                      {:controller=>"carts", :action=>"edit"}
GET    /carts/:id(.:format)                           {:controller=>"carts", :action=>"show"}
PUT    /carts/:id(.:format)                           {:controller=>"carts", :action=>"update"}
DELETE /carts/:id(.:format)                           {:controller=>"carts", :action=>"destroy"}
cart        /cart           {:controller=>"carts", :action=>"show"}
A: 

If you don't need the id in the routes, you could use:

map.resource :cart, :controller => :carts
jordinl
replacing my two routes with what you suggested worked great, thanks, but i don't really understand why. Were my routes conflicting?
Jon
what was the output of 'rake gems' with the old routes?
jordinl
did you mean "routes"?
Jon
oooooops, yes routes........
jordinl
updated original question
Jon
I can't see why it should crash with the routes you had defined, can you show me a trace of the error you got?
jordinl