简体   繁体   中英

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM