I have a bunch of check boxes which represent each day of the week... The user can check one or more days of the week. How should I store it in my database? A field with "days" and a numerical representation of each day? so if they check monday and it tuesday it would store 12? I'm not sure what the most optimal way of doing this is. Thanks.
2 Answers
If you don't need do some search on it, you can use the serialize method to serialize in Array your output. You can do like that
serialize :days, Array
With this configuration, the day are save like a String in your database. This string is a Yaml representation of your Array. So when you get days from your model. You have an Array like result.
1 Comment
Ben Frank
I need to perform searches on it
I recommend to read http://en.wikipedia.org/wiki/Database_normalization.
Personally, I'd store it with a datetime field and a user_id field. That's it. This my produce more data, but extending it with searches etc is easier.