Add a new page to a resource in rails
Ok, This seem so simple that I feel kind of dumb f开发者_开发问答or asking, yet I have seen other that asked something similar but no quite the same and their answers does not solve my problem. I have a resource called servicios.
resources :servicios, created the routes for the "default" actions that are in my controller: index, new, create, show, edit, update, destroy. However, I need another action which is search that should map to my view where I'm going to implement an advance search.
How can I do that?
Editing with new info using this approach: resources :servicios, :collection => {:search => :get} http://localhost:3000/servicios/search I was getting error ActiveRecord::RecordNotFound in ServiciosController#show Couldn't find Servicio with ID=search
If you are using Rails 3 then the route definitions will look like
resources :servicios do
collection do
get :search
end
end
resources :servicios, :collection => {:search => :get}
Will route /servicios/search to def search...end
in the servicios controller.
Or...
match 'search', :to => 'servicios#search'
精彩评论