named routing doesnt work in rails3
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
.
精彩评论