我有一个资源,我已设置为在 url 中使用 :slug 而不是 :id 。
我的rake routes样子
Prefix Verb URI Pattern Controller#Action
root GET / home#index
home GET / home#index
course_type GET /courses/:slug(.:format) course_type#show
但是,当我这样做时,在我的模板(haml)中
= link_to course_type.name, course_type
它链接到 /courses/1(course_type有id:1和slug:"type_a")。它不应该指向/courses/type_a吗?
我也尝试过使用show_course_type_path,[:show, course_type]但他们都提出了undefined method: show_course_type_path
如何让 rails 生成正确的路径?