I think the easiest thing to do is to have each attribute represented as
a column in your scheme. So instead of having one column,
“ideal_body_type” have one for skinny, fat, super man, each holding a
On validation, you can make sure atleast one of them is checked:
flag - 0
[:skinny, :fat, :super_man].each |body_type|
flag += 1 unless send(body_type).nil?
return false if flag.zero? else true
ok, so the example is cracked but the idea is somewhere in there…
I am trying to create a form for a dating site where users can specify
the body types they seek in their ideal match (ex: Slender, slim,
average, fat, etc.). Since users may be attracted to more than one body
type, they are allowed to check multiple boxes.
In my SQL schema, I’ve defined this attribute as “ideal_body_type”. How
should I store and validate this aggregated data in my model. Also, if
an error occurs during validation, how do I make the checked values in
these checkboxes stay checked?
Thanks in advance.