Mat*_*Mat 3 routes ruby-on-rails
我目前在我的routes.rb:
namespace :api
namespace :v1
namespace :me
# ...
resources :offers do
resources :state, only: %i(index)
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
这给了我这条路线:
GET v1/me/offers/:offer_id/state(.:format)
api/v1/me/state#index
Run Code Online (Sandbox Code Playgroud)
但我想要的路线是这样的:
GET v1/me/offers/:offer_id/state(.:format)
api/v1/me/offers/state#index
Run Code Online (Sandbox Code Playgroud)
简单地说,我希望能够将我的state_controller.rb放在一个offers文件夹中,而无需更改访问它的路径。我怎样才能做到这一点?
我找到了一个更好的方法:使用 module
resources :offers, module: :offers do
resources :state, only: %i(index)
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1476 次 |
| 最近记录: |