开发者

named routing doesnt work in rails3

开发者 https://www.devze.com 2023-02-07 08:18 出处:网络
Hey, I want to name my route using the :as parameter. Ive read the Rails Routing Guide about this but unfortunately it wont display me /my_courses in the开发者_运维知识库 url

Hey, I want to name my route using the :as parameter. Ive read the Rails Routing Guide about this but unfortunately it wont display me /my_courses in the开发者_运维知识库 url

match 'course_enrollments', :to => 'course_enrollments#index', :as => 'my_courses'

thx for your time!


match 'my_courses', :to => 'course_enrollments#index', :as => 'my_courses'

This will route /my_courses to the index action of your CourseEnrollments controller, and allow you to refer to the path by referencing my_courses_path or my_courses_url in your views and controllers.

To clarify: The first parameter in match is what maps the route to an actual URL. The :as option simply allows you to override the name of the route helper.


That matches course_enrollments in the URL, not my_courses. The :as parameter means you can refer to the route in views using (in this example) my_courses_path.

0

精彩评论

暂无评论...
验证码 换一张
取 消