1

I am currently building a Ruby on Rails application for students to book workshop classes with instructors. I am seeking some advice regarding the models setup.

I have already looked at this & this stack overflow threads, but they do not answer my questions.


Functionality required:

  • Instructor needs to be able to set weekly-repeating timeslots available for booking
  • Instructor needs to be able to open up additional one-off timeslots in addition to the weekly-repeating slots
  • Instructor needs to be able to remove available timeslots on a one-off basis, e.g. when instructor goes on vacation
  • Classes are not limited to one student, classes can have as many students as the teacher wishes
  • All classes are one-hour long, so only start time needs to be considered

My current proposal:

I'm considering setting it up three models and three tables. The three models all connect to the same workshop controller.

Example data uses the following scenario: Tom has classes every Mon & Tue 9am, but for next week only, he is switching his Tue classes to be held on Wed.

The idea is that I have a model that lists all the teachers' classes. I have another model for the recurring timeslots for each of the teacher's classes. I then have a third model for exceptions that acts as a list of 'changes' to the weekly-repeating classes times:

workshop model linked to workshop table:

ID | Workshop Name | Price
1  | Tom's Class   | 100

workshop_times_recurring model linked to workshop_times_recurring table:

ID | Workshop ID | Times
1  | 1           | {Monday 0900, Tuesday 0900}

workshop_times_other model linked to workshop_times_other table:

ID | Workshop ID | Type    | Time
1  | 1           | Active  | {2017May31 09am}
2  | 1           | Inactive| {2017May30 09am}

My questions are:

  1. Is this the most elegant way to set up the models for my app and I'm not completely off-track? If not, what is a better solution?
  2. I am hoping that I am able to parse strings like 'Monday 0900, Tuesday 0900' and '2017May31 09am' such that information can be shown correctly on a javascript-driven datetime selection calendar. Will my current setup allow me to achieve this on the frontend?
mikez
  • 35
  • 1
  • 6

1 Answers1

2

To primarily answer your second question, I propose to use an established format for repeating schedules, like the OpenStreetMap Opening Hours format. There's also a JavaScript library for it.

But since it can also deal with exceptions to the regular schedule, it would probably simplify your model quite a bit, too.

Marcus Ilgner
  • 6,935
  • 2
  • 30
  • 44