如何创建 ID 值超过 1 的 Rails 资源路由?
示例:
您有一个名为 widget
的资源,它的 ID 是 2 个字符串:“foo”和“bar”。
你能有这样的网址吗?
Index: http://domain.com/widgets
New: http://domain.com/widgets/new
Create: http://domain.com/widgets
Show: http://domain.com/widgets/foo/bar
Edit: http://domain.com/widgets/foo/bar/edit
Update: http://domain.com/widgets/foo/bar
Destroy: http://domain.com/widgets/foo/bar
或者我必须手动制作这些?
最佳答案
resources :domains, only: [:index, :new, :create]
get 'widgets/*id', to: 'widgets#show'
get 'widgets/*id/edit', to: 'widgets#edit'
put 'widgets/*id', to: 'widgets#update'
delete 'widgets/*id', to: 'widgets#destroy'
您将得到 params[:id] 作为 'foo/bar'
关于ruby-on-rails - Rails 资源路由具有多个值的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22331873/