scope
一、不使用 scope
resources :jjs默认对应:
jjs GET /jjs(.:format) jjs#index
POST /jjs(.:format) jjs#create
new_jj GET /jjs/new(.:format) jjs#new
edit_jj GET /jjs/:id/edit(.:format) jjs#edit
jj GET /jjs/:id(.:format) jjs#show
PATCH /jjs/:id(.:format) jjs#update
PUT /jjs/:id(.:format) jjs#update
DELETE /jjs/:id(.:format) jjs#destroy二、使用 scope,但不传递参数
scope "/admin" do
resources :iis
end默认对应:
iis GET /admin/iis(.:format) iis#index
POST /admin/iis(.:format) iis#create
new_ii GET /admin/iis/new(.:format) iis#new
edit_ii GET /admin/iis/:id/edit(.:format) iis#edit
ii GET /admin/iis/:id(.:format) iis#show
PATCH /admin/iis/:id(.:format) iis#update
PUT /admin/iis/:id(.:format) iis#update
DELETE /admin/iis/:id(.:format) iis#destroy可以看出,只影响最外面的网址。
三、使用 scope,并传递参数
接受参数:path、constraints、shallow_path、shallow_prefix、defaults、as、module、controller 等。
1) :as 参数
3 个很重要的参数之一
影响中间层
2) :path 参数
3 个很重要的参数之一
影响最外层
3) :module 参数
3 个很重要的参数之一
影响最里层
4) :path、:as 和 :module 参数
等价于
namespace :admin
5) :defaults 参数
对应着 defaults 方法。(它是通用的,类型为 Hash.)
6) :constraints 参数
对应着 constraints 方法。
7) :controller 参数
对应着 controller 方法。
最后更新于
这有帮助吗?