开发者

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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜