I am building a site where users can take various sequences of courses and I am struggling to figure out the schema. So far I have this:
has_many :assigned_lessons, through: :active_courses
I fear this is over-complicated. Is there a more simple way to structure an application of this sort? I need the lessons in each course to have a particular order - which can be chosen by the admin when they create a course. And I need to be able to mark
active lessons and
assigned courses as completed. Any advice much appreciated!
Doesn’t look obviously over-complicated to me.
I might call
Enrollment instead, but that’s a personal call.
I’d say start building and see how this works out for you.
Thanks for your response Ben. Something I am struggling with is how to handle the ordering of lessons in the course. I can’t have an order attribute in my
Lesson class because lessons might be in more than one course. Any advice?
@charliegaines, maybe a
Syllabus model that holds
Lesson order in relation to
Course or, in case, an entity responsible for that order?
Yeah, I’d likely do what @pedromoreira is suggesting.
Thanks fellas. So…a
Course would have one
Syllabus has many
Lessons. How would I store the order in
The direction I was going in was to have a
CourseLesson join model with an
:order attribute on that model. I haven’t managed to figure out how to set the order in my
Course#new form though. I tried this:
<%= check_box_tag "course[lesson_ids]", lesson.id %>
<%= lesson.title %>
<p>Order of lesson in course:</p>
<%#= number_field_tag "course[lesson_order]", in: 1...8 %>
But no luck. My terminal output:
"lesson_ids"=>["1", "2", "3"],
"lesson_order"=>["2", "1", "3"]}
Any tips? Thanks again for your help.
@pedromoreira, if I take the
Syllabus approach, how would you store the order? It seems the simplest approach is to store the meditations ids in a postgres array. But I could just do that in my
Course class and dispense with
@charliegaines, domain modelling questions are always tricky.
CourseLesson approach is the same as
Syllabus: the difference being the naming and clarity it adds or not to your domain model. From the information you presented, I would store the order as an attribute in a join model, just as you suggested, since I don’t know enough about your application to say otherwise.
You mentioned you were having problems with that approach in that you aren’t sure how to handle the new
Course form. It appears you are making a form that creates the Course and adds in the lessons in order. Maybe you can expose more of your problem with that? It is something that is easier to get help with
@pedromoreira, yes they are tricky - but also interesting! Thanks for your response, I will keep hacking away.
@benorenstein, would you consider doing some weekly iterations or a series of screencasts on the topic? Maybe do it Iron
Chef Developer style, have two developers tackle a tricky domain and compare results. I think that would be interesting.
@charliegaines, you’re welcome. Hope I helped a bit