Monday, May 5, 2014

Nested RESTful Routes

Let's say Lessons has a  has_many relationship to Courses and you want to do #show on method in the view. Here is a view of the path:

course_lesson GET      /courses/:course_id/lessons/:id(.:format)      lessons#show

What you will need to do is:

<%= link_to "#{lesson.description}", course_lesson_path(lesson.course, lesson) %>

This will allow the link to populate both the :course_id as well as the :id of the lesson.

No comments:

Post a Comment