small medium large xlarge

Generic-user-small
29 Jan 2012, 23:25
Shaban Karumba (6 posts)

Hi ,

I am having problems with my cart basically what happens is when I add an item to the cart its added to the shopping cart and I then return to the catalogue and add a different item or the same item but each time a new cart is created. I can see by the cart number as it increases each time. I am using safari on my mac to view the site . What could be the problem?

Generic-user-small
31 Jan 2012, 15:27
Svetoslav Dankov (3 posts)

For a start, check what method you are calling when the “Add to cart” button is clicked. What happens after you click it should be defined in the “create” method in the line_items_controller. Make sure you are adding a line_item to the “current_cart” (which comes from your session) and not a new cart. You should also check if your “current_cart” (defined in the application_controller) method is doing what it’s supposed to do.

Just a guess.

Generic-user-small
31 Jan 2012, 17:55
Shaban Karumba (6 posts)

Fixed the issue i used card_id instead of cart_id in the line session[:cart_id] = cart.id for the application controller .

Now the next issue is if I type /carts into the browser when to view my application I can see all my previous carts with the Show, Edit and Destroy button? How would i make this hidden?

Generic-user-small
03 Feb 2012, 21:08
farout (5 posts)

Not sure why you are trying to do this. Later in the book there are chapters users access which can be used by adding the “before_filter :authorize” to the controllers and their methods for restriction.

However if you just want to restrict access, per the http://guides.rubyonrails.org/routing.html 4.6 Restricting the Routes Created section, change this line:

resources :carts

to this:

resources :carts, :except => [:index, :show]

You must be logged in to comment