small medium large xlarge

Generic-user-small
01 Sep 2008, 17:26
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_pragsmall
01 Sep 2008, 17:47
Sam Ruby (634 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
01 Sep 2008, 23:49
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_pragsmall
02 Sep 2008, 15:45
Sam Ruby (634 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
06 Sep 2008, 14:16
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
06 Sep 2008, 23:36
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
09 Oct 2008, 21:46
Jason Franklin-Stokes (4 posts)

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

You must be logged in to comment