Validation of models

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:

New Question

<%= error_messages_for :question, :header_message => "Please try again!", :message => "Amend the following errors:" %> <% form_for(:question, :url => questions_path) do |f| %>

Domain:
<% @domain.each do |domain| %>

<%= check_box_tag "question[domain_ids][]", domain.id, @question.domains.include?(domain) %> <%= h(domain.name) %> <%= image_tag("#{domain.imagename}")%>
<% end %>

Question:
(Keep it short and simple!)
<%= f.text_field :question, :size => '60' %>

<%= submit_tag "Submit" %>

<% 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.