title: How to validate empty Select box option with Ruby on Rails?
body: <p>I have a very simple <code>Project</code> form with a <code>name</code> field and a select box with various <code>Client</code> names in it: </p>
  
  <pre><code>&lt;%= f.label :name %&gt;&lt;br/&gt;
  &lt;%= f.text_field :name %&gt;
  
  &lt;%= f.label :client_id %&gt;&lt;br/&gt;
  &lt;% options = current_user.clients.all.map { |client| [client.name, client.id] } %&gt;
  &lt;%= f.select(:client_id, options, {:prompt =&gt; 'Select...'}) %&gt;
  </code></pre>
  
  <p>Now when a user hits submit without actually selecting a <code>Client</code> from the select box, an error is returned saying that a <code>Client</code> with ID " " cannot be found.</p>
  
  <p>Is there any way to change my controller code so that it works?</p>
  
  <pre><code>def create
    client = current_user.clients.find(params[:project][:client_id])
    @project = client.projects.build(params[:project])
    if @project.save
      flash[:success] = "Project created."
      redirect_to @project
    else
      render :action =&gt; "new"
    end
  end
  </code></pre>
  
  <p>It's the local <code>client</code> variable that causes the trouble but I don't know how to fix it so that errors will be handled by the validation methods.</p>