【发布时间】:2019-01-10 15:06:57
【问题描述】:
我在 routes.rb 中定义了自定义 URL 路径,但我的 _path 和 _url 助手会产生额外的错误路由。
routes.rb
get '/:id', to: 'groups#show', constraints: proc {|req| FriendlyId::Slug.where(sluggable_type: 'Group').pluck(:slug).include?(req.params[:id])}, as: :group
get '/:id', to: 'custom_pages#show', constraints: proc {|req| FriendlyId::Slug.where(sluggable_type: 'CustomPage').pluck(:slug).include?(req.params[:id])}, as: :custom_page
get ':group_id/:id', to: 'exams#show', constraints: proc {|req| FriendlyId::Slug.where(sluggable_type: 'Exam').pluck(:slug).include?(req.params[:id])}, as: :exam
预计路线:
- /自定义/
- /测试/
- /测试/考试/
实际路线:
- /自定义/
- /测试/
- /test/exam/(加载,但未定义
_path或_url) - /exam/(为
_path和_url定义)
所以所有需要的路由都会加载,但 _path 和 _url 帮助程序持续显示错误的考试路径 (/exam/) 尽管不在 routes.rb 中。 :/
我做错了什么?
【问题讨论】:
-
如何称呼这些助手?
exam_path(some_id, group_id:'test')?
标签: ruby-on-rails