开发者

to_sym error when using sessions

开发者 https://www.devze.com 2023-01-16 04:04 出处:网络
I have a \"cart\" model, a users cart id is stored in their session. My routes look like this map.resources :carts

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"}


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

map.resource :cart, :controller => :carts
0

精彩评论

暂无评论...
验证码 换一张
取 消