I have 2 models;
1. Question : has_and_belongs_to_many :domains
2. Domain : has_and_belongs_to_many :questions
When a user submits a new question, the domains appear as a list of
check boxes to select, here is the new question form:
<h1>New Question</h1>
<%= error_messages_for :question, :header_message => "Please try
again!", :message => "Amend the following errors:" %>
<% form_for(:question, :url => questions_path) do |f| %>
<p>
Domain:<br />
<% @domain.each do |domain| %>
<div>
<%= check_box_tag "question[domain_ids][]", domain.id,
@question.domains.include?(domain) %>
<%= h(domain.name) %> <%=
image_tag("#{domain.imagename}")%>
</div>
<% end %>
</p>
<p>
Question:<br />
(Keep it short and simple!)<br />
<%= f.text_field :question, :size => ''60'' %>
</p>
<p>
<%= submit_tag "Submit" %>
</p>
<% end %>
My question is how to ensure that a user selects a domain in order for
the question to be successfully submitted.
In the question model i have tried:
validates_presence_of :domain
But that does not quite work. If a domain is not selected the question
will not be created, however if the user does select a domain, i still
get a validation error "Domain can''t be blank"!
Any help appreciated,
PJ.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---