title: What causes a 422 Unprocessable Entity Error in Rails 3?
body: <p>This is the error message from the logfile:</p>
  
  <pre><code>Started POST "/stages" for 127.0.0.1 at 2011-04-02 23:22:18 -0500
  Processing by StagesController#create as JS
    Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"ob37MMciudHqAnNXFoeofWyVfLnrTxlHfncyDsZLpsI=", "stage"=&gt;{"project_id"=&gt;"3", "name"=&gt;"First"}}
  
    User Load (1.1ms)  SELECT "users".* FROM "users" WHERE ("users"."id" = 1) LIMIT 1
  #&lt;User id: 1, email: "test@abc.com", encrypted_password: "$2a$10$qUbNGm6lZ366jRiE0vK0gOpxbGXD5JmfqWmH1lfLlCEC...", password_salt: "$2a$10$qUbNGm6lZ366jRiE0vK0gO", reset_password_token: nil, remember_token: nil, remember_created_at: nil, sign_in_count: 264, current_sign_in_at: "2011-04-03 04:12:24", last_sign_in_at: "2011-04-03 03:21:37", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", username: "test", f_name: "Test", l_name: "User", created_at: "2011-01-22 07:17:45", updated_at: "2011-04-03 04:12:24", invitation_token: nil, invitation_sent_at: nil, plan_id: 3, current_state: nil, confirmation_token: nil, confirmed_at: "2011-02-11 23:19:15", confirmation_sent_at: "2011-02-11 23:18:20"&gt;
  
    Role Load (0.4ms)  SELECT "roles".* FROM "roles" INNER JOIN "assignments" ON "roles".id = "assignments".role_id WHERE (("assignments".user_id = 1))
  Completed 422 Unprocessable Entity in 302ms (Views: 0.2ms | ActiveRecord: 1.5ms)
  </code></pre>
  
  <p>Any ideas ?</p>
  
  <p>This is the new &amp; create actions in stage:</p>
  
  <pre><code>def new
      @project = Project.new
      respond_with(@project)
    end
  
  def create
      #@project = current_user.projects.create(params[:project])
      @project = current_user.projects.build(params[:project])
      #@project.current_user = current_user
      if @project.save
        respond_with(@project, :status =&gt; :created, :location =&gt; @project) do |format|
          flash.now[:notice] = 'Project was successfully created.'
          format.html { redirect_to(@project) }
          format.js   { render :partial =&gt; "projects/show", :locals =&gt; {:project =&gt; @project}, :layout =&gt; false, :status =&gt; :created }
        end
      else
        respond_with(@project.errors, :status =&gt; :unprocessable_entity) do |format|
            format.js   { render :json =&gt; @project.errors, :layout =&gt; false, :status =&gt; :unprocessable_entity }
            format.html { render :action =&gt; "new" }
        end
      end
    end
  </code></pre>
  
  <p>This is the form partial that creates the new stage:</p>
  
  <pre><code>&lt;% stage ||= Stage.new 
     new_stage = stage.new_record? %&gt;
  &lt;%= form_for(stage, :html =&gt; { :class=&gt;"ajax-form", :id =&gt; "stage-ajax-form"}, :remote =&gt; true, :disable_with =&gt; (new_stage ? "Adding..." : "Saving...")) do |f| %&gt;
      &lt;%= f.hidden_field :project_id %&gt;
      &lt;%#= f.hidden_field :client_id, :value =&gt; @project.client.id %&gt;
      &lt;div class="validation-error" style="display:none"&gt;&lt;/div&gt;
      &lt;label for="stage_name"&gt;&lt;span class="icon stage-icon"&gt; &lt;/span&gt;&lt;/label&gt;
      &lt;input type="text" class="name" size="20" name="stage[name]" id="stage_name" value="&lt;%=  stage.name %&gt;" &gt;
  
      &lt;%= f.submit(new_stage ? "Add Stage" : "Save", :class =&gt; "green awesome") %&gt;
  &lt;% end %&gt;
  </code></pre>