I can't figure out how to do this in rails 3.0. I have a controller, products
, and an action, search
, and in routes.rb
I've tried
resources :products, :collection => {:search => :post }
and
match 'products/search' => 'products#search', :via => [:get, :post]
and many other settings, but whenever I access products/search
I still get an error complaining that the Product with id, search
, can't be found for the action show
. Anyone know what I'm doing wrong?
Thanks.
You're close.
resources :products do
collection do
match 'search', :via => [:get, :post]
end
end
Alternatively, you could also do:
resources :products do
match 'search', :on => :collection, :via => [:get, :post]
end
See Rails Routing from the Outside In of the Edge Guides for more information, more specifically:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With