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
boolean value.
On validation, you can make sure atleast one of them is checked:
before_save :confirm_body_type
def body_type
flag - 0
[:skinny, :fat, :super_man].each |body_type|
flag += 1 unless send(body_type).nil?
end
return false if flag.zero? else true
end
ok, so the example is cracked but the idea is somewhere in there...
Jesse wrote:> Hi,
>
> 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.
>
> -Jesse
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---