Rails List wrote:
> BenR wrote:
>> have the following in a partial
>> <% OrganisationType.find_all_by_live(true).each do |ot| %>
>> <%= check_box_tag "organisation['organisation_type_ids'][]", ot.id,
>> @organisation.have_org_type(ot.id, @organisation.id) %>
>> <%= ot.name %>
>> <% end %>
>>
>> in the Organisation model I would like to validate that at least one
>> of the checkboxes is checked. I am sure this is simple, but, er, I am
>> simpler ...
>> Any one able to point me in the right direction?
>>
>> many thanks
>> Ben
Ben, In your model, you can create a method something like
#your model
validate :one_must_be_checked
def one_must_be_checked
unless chkbox1 || chkbox2 || chkbox3
errors.add_to_base "One of the Checkboxes must be accpeted"
end
end
Let me know how it goes...
http://www.classifiedscript.in
Craigslist classifieds clone in Rails
--
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---