Jump to content

The ultimate community for Ruby on Rails developers.


Business Hours Schema?

  • Please log in to reply
1 reply to this topic

#1 hellomello



  • Members
  • 18 posts

Posted 13 October 2013 - 07:06 AM

Is there a gem or tutorial on how to make a business hours schema? 


If there are many businesses, with many hours, whats the best database schema for this case?


Is there a way to save an array of hours into record database cell for a business? Or would you have to make a new table just for hours?

#2 Jamie



  • Moderators
  • 142 posts
  • LocationNewcastle, UK

Posted 13 October 2013 - 09:14 AM

Yeah you could save them as an array inside a TEXT column in your business model just called 'opening_hours' or something.


You could go as far as having a HABTM relationship as I assume some businesses would have different opening hours but some might be the same so you could have relationships there.


For something so small that doesn't require any interaction from the user I would just go with saving them as an array.


You can then just loop through the array to print out the day and hours. Key/Value association.


It just would appear to be more code than necessary for opening hours. But I might be wrong and not understood the question.


Have a nice day :)

Rails developer based in Newcastle, UK.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users