如何删除路径中参数的 routes.rb 中生成的前缀
How to remove the prefix generated in routes.rb for the params in the path
目前在我的路线中我有:
# USER RESOURCES
resources :users do
resources :repositories
patch 'change_password'
get 'account_setting'
end
为 account_setting
操作生成此路径:
user_account_setting GET /users/:user_id/account_setting(.:format) users#account_setting
我想要的是:
user_account_setting GET /users/:id/account_setting(.:format) users#account_setting
两者本质上是一样的,但第一个有一个 id
的 user_
前缀,rails 添加是因为它在用户资源块中。
旁注
我知道我可以简单地从用户资源块中删除 account_setting
操作并写入:
get 'users/:id/account_setting', to: 'users#account_setting'
但我不想。
您可以按照以下方式进行:
resources :users do
member do
get 'account_setting'
end
end
要添加成员路由,请将成员块添加到资源块中。
有关文档,您可以查看http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html
目前在我的路线中我有:
# USER RESOURCES
resources :users do
resources :repositories
patch 'change_password'
get 'account_setting'
end
为 account_setting
操作生成此路径:
user_account_setting GET /users/:user_id/account_setting(.:format) users#account_setting
我想要的是:
user_account_setting GET /users/:id/account_setting(.:format) users#account_setting
两者本质上是一样的,但第一个有一个 id
的 user_
前缀,rails 添加是因为它在用户资源块中。
旁注
我知道我可以简单地从用户资源块中删除 account_setting
操作并写入:
get 'users/:id/account_setting', to: 'users#account_setting'
但我不想。
您可以按照以下方式进行:
resources :users do
member do
get 'account_setting'
end
end
要添加成员路由,请将成员块添加到资源块中。
有关文档,您可以查看http://api.rubyonrails.org/classes/ActionDispatch/Routing/Mapper/Resources.html