[Rails] need some help with routes maybe
Im making a Cart for my site, so I make Orders Controller to manage
Orders
so inside I do
def add_product
@product = Product.find(params[:id])
@order = Order.find_by_client_id(current_user.id)
@order.products << @product
end
on Product view/show I place
<%= link_to t(:add_to_cart), order_add_product_path(@product) %>
config/routes
resources :orders do
get :add_product
end
But i kept getting
http://localhost:3000/orders/3/add_product
ActiveRecord::RecordNotFound in OrdersController#add_product
Couldn't find Product without an ID
model:
orders has_and_belongs_to_many :products
products has_and_belongs_to_many :orders
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home