last day (14 days later) » 

4:31 PM
3
A: How should I store a collection for an attribute in Rails?

Maxim PontyushenkoIf according to business logic you are planning to have some attributes, methods or other things for each of your categories, you should create another model for Category. It would be less hard to implement your future needs in terms of managing complexity. If you are 100% sure that there will be...

 
Could you provide an example? Not sure I fully understand (newbie sorry)
 
@Matthias For example your categories would have some attributes as well. Maybe size or price_range, etc. Instead of storing it in every object of particular category you could store it once if your category is separate object.
 
Ok, I understand. The categories have no attributes of their own
 
@Matthias then you should check Brad's answer. It provides an example of validation.
 
Ok thanks. Sorry to bother you. An alternative that I was thinking of was to pair the option value with an integer key and thus only store the integer in the db. This will keep some flexibility in the naming later. What do you think of this?
 
4:31 PM
@Matthias could you give more detailed explanation? Did not get it.
 
Well you could create a hash such as ['Option 1', 0], ['Option 2', 2]. The form would display the key Option 1 and store the value 1 in the database. I imagine this would have some benefits, but not sure if this is customary
Hi, wouldn't want to take up too much of your time of course
 
Although I still don't get it, I don't see any major benefits from such an approach. What kinds of benefits are you looking for?
 
the attribute would be set as an integer
 
Do you want to save some disk space by it?
 
I'm thinking more in the line of flexibility or i18n
but I understand this is not customary
 
4:35 PM
To me it sounds more like extending complexity
 
ok, so strings it is then :-)
 
There is no problem with I18n since you know locale
 
Thanks Maxim
 
And don't forget
to test behavior of your code with spec. And to add validations)
 

last day (14 days later) »