Restricting resource routes and adding additional non-RESTful routes in Rails 3

不问归期 提交于 2019-12-05 02:40:33

You can pass arguments and a block to resources:

resources :sessions, :only => [:new, :create, :destroy] do
  get :recovery, :on => :member
end

And test it out with rake routes.

It should be working pretty much like this

resources :sessions, :only => [:new, :create, :destroy] do
  member do
    get :recovery
  end
end

There is an even shorter way, as proposed by coreyward.

Check the rails guides, "Rails Routing from the Outside In". I also can recommend "The Rails 3 Way" by Obie Fernandez, which got 2 pretty good chapters on Routing and RESt.

Cheers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!