title: Rails 3 remote form: How do I specify the content type?
body: <p>I am using Rails 3.2, I have a form and I want it to be posted via ajax and have the controller return json. </p>
  
  <p>I am using a form_for helper like so:</p>
  
  <pre><code>= form_for(@object, :remote =&gt; true, :format =&gt; :json) do |f|
  ....
  </code></pre>
  
  <p>My objects controller create method looks like this:</p>
  
  <pre><code>  def create
      respond_to do |format|
        if @object.save
           format.html { redirect_to @object }
           format.json { render json: @object, status: :created, location: @object }
        else
          format.html { render action: "new" }
          format.json { render json: @object.errors, status: :unprocessable_entity }
        end
      end
    end
  </code></pre>
  
  <p>The form is submitting ajaxly as expected. But the controller is returning html, not json!</p>
  
  <p>Inspecting the request with firebug and sure enough the Content-Type http header on the ajax request is being set to application/html.</p>
  
  <p>The documentation around this is pretty sparse, :format => :json seems to just append ".json" to the forms action, not actually modify any http headers.</p>
  
  <p>I've also tried :content_type => :json to no effect.</p>
  
  <p>I can't simply hard code the controller to return json as there are other places where I do want it to return html...</p>
  
  <p>So does anyone know how to tell the controller to render json when using form_for?</p>
  
  <p>Thanks for any help</p>