title: How does rails determine incoming request format?
body: <p>I'm just wondering how rails knows the format of the request as to correctly enter in the famous: </p>
  
  <pre><code>respond_to do |format|
    format.html
    format.xml
    format.json
  end
  </code></pre>
  
  <p>As an example consider this situation I have faced up. Suppose that via javascript (using jQuery) I make a POST request expliciting <strong>dataType: json</strong></p>
  
  <pre><code>$.ajax({
        type: 'POST',
        url: 'example.com',
        data: data,
        dataType: 'json'
      });
  </code></pre>
  
  <p>When this request reach controller action, standing inside it with ruby debugger, I inspect @request.format and I can see that content-type is application/json. Then the controller respond to json format as expected. </p>
  
  <p>But I'm confused with the format symbol especified in the routes. Suppose that a request is made to <strong>example.com/parts.json</strong> but in the request the content type is application/html or application/xml. <strong>Is the controller responding to json format or html or xml??</strong></p>
  
  <p>Thanks!</p>