I’m working on a Rails app for online courses. I’ve got models for Course, CourseStep, Step, CourseEnrollment, and Patient. Right now, I can show a list of courses a user is enrolled in and the latest course overview.
But I’m stuck on how to display individual course steps. Should I use the course_steps controller for this? It’s nested under the courses resource.
Here’s what I’ve figured out so far:
- /course_enrollments/ shows enrolled courses and the latest overview
- /course_enrollments/:id displays enrolled courses and a course overview
Any tips on the best way to structure this? I want to make sure I’m following Rails best practices. Thanks!
Hey MaxRock56! Interesting project you’ve got there. 
I’m curious about how you’re handling user progression through the course steps. Have you considered using a separate controller for that?
Maybe something like a CourseProgressController could be useful. It could handle stuff like:
/courses/:course_id/progress
This could show the user’s current progress in the course, including completed and upcoming steps. You could even add actions for marking steps as complete or accessing the next step.
What do you think about this approach? It might help keep your course_steps controller focused on CRUD operations for admins, while this new controller handles the user’s journey through the course.
Oh, and have you thought about gamification at all? Like awarding badges for completing certain milestones in a course? That could be a fun addition!
Let me know what you think. I’d love to hear more about how your project develops!
I’ve implemented a similar structure in my Rails app for a professional development platform. Here’s what worked well for me:
Use the course_steps controller, but consider adding a dedicated CoursesController#show action for displaying the course overview and its steps. This approach keeps your routes clean and follows the principle of skinny controllers, fat models.
In CoursesController#show, you can load the course and its associated steps:
@course = Course.find(params[:id])
@steps = @course.course_steps.includes(:step)
Then in your view, iterate through @steps to display each one. This method is efficient and scalable as your app grows.
Remember to implement proper authorization to ensure users can only access courses they’re enrolled in. The Pundit gem is excellent for this if you’re not already using it.
hey MaxRock56, sounds like ur on the right track! for showing individual course steps, i’d suggest using the course_steps controller. you could add a show action like this:
/courses/:course_id/course_steps/:id
this keeps things RESTful and nested properly. good luck with ur project!