Routing concerns defining different param for resources

爱⌒轻易说出口 提交于 2019-12-04 07:47:01
Cyril Duchon-Doris

Yes I remembered seeing something about this. It wasn't in the Rails guide, but an answer to a SO question that kinda surprised me. You can use a block : (quoted from the aforementionned answer)

In Rails 4 you can pass options to concerns. So if you do this:

# routes.rb
concern :commentable do |options|
  resources :comments, options
end

resources :articles do
  concerns :commentable, commentable_param: 'slug'
end

Then when you rake routes, you will see you get a route like

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