Topic: Route error
Hello, I'm new with rails ( rails 3.0 ) and i try to realize the depot application from " agile web development with rails ". I've got a problem on the iteration C1, creating a cart ! So I want to create a list product with a button to adding the product on the cart .
I realize my controller store_controller :
class StoreController < ApplicationController
@products = Product.a_vendre
product = Product.find(params[:id])
@cart = find_cart
session[:cart] ||= Cart.new
I realize my view add_to_cart :
<h2>Your Pragmatic Cart</h2>
<% for item in @cart.items %>
<li><%=h item.title %></li>
<% end %>
And somewhere in the index page i put a button for adding product to cart :
<%= button_to "Add to Cart", :action => 'add_to_cart', :id => product %>
When i push the button, i've a redirection to "http://localhost:3000/store/add_to_cart?id=6", i think it's the good url but i've got the error :
No route matches "/store/add_to_cart"
When i refresh the url, it does what i want, without error...
So, I think the route "store/add_to_cart" is find, but i don't know the error so... probably the button ...
I generate routes with "rake routes " and in routes.rb :
Please help me, I work with Rails 3.0 ... And sorry if my english is not to perfect, i'm french...
PS : Sorry for the place, if an admin can put it in Controller and view ... !
Last edited by kevin.guilbert62 (2011-08-01 07:27:48)