Generic-user-small SA 4 posts

I tried to add the cart, but when I clicked ont he add_to_cart button, nothing changed. I tried to manually load the add_to_cart.html.erb page and got the following error:
No route matches ”/add_to_cart” with {:method=>:get}

I restarted Mongrel and tried again. Same error. Any ideas?

Thanks:)

Sa

 
Samr_small_small Sam Ruby 197 posts

I like your approach to debugging, trying it manually and then comparing it to what the application is trying to do. Let’s go with that.

But it looks to me like you have the URI wrong. The following should add product #2 to the cart:

http://localhost:3000/store/add_to_cart/2

 
Generic-user-small SA 4 posts

Interestingly enough, when I try to manually load http://localhost:3000/store/add_to_cart/2 , I get redirected back to http://localhost:3000/store.

Any ideas?

Thanks:)

Sa

 
Samr_small_small Sam Ruby 197 posts

OK, so get properly redirects, lets try post. Add the following as public/testadd.html:

<form action="/store/add_to_cart/2">
  <input type="submit">
</form>

Then go to http://localhost:3000/testadd.html, and press Submit.

 
Generic-user-small SA 4 posts

I added the testadd page and clicked on the submit button. I was redirected to http://localhost:3000/store. This is the same as any other cart adds.

 
Generic-user-small SA 4 posts

I think I found my error. I had :id in the index.html.erb file and :object_id in the controller. Once I change :object_id to :id and restarted, everything is now working.

Thanks:)
Sa

 
Generic-user-small Jason Frankl... 4 posts

just an after note: when ever you make any changes to routes.rb always resart the server.

7 posts, 3 voices