title: How does respond_to and respond_with work in rails?
body: <p>When there is </p>
  
  <pre><code>def some_action
    respond_to do |format|
      format.html {}
      format.js {}
      format.json { respond_with @objects}
    end
  end
  </code></pre>
  
  <p>It seems like html line and the js line automatically serve up/call the file matching the action's name. And the html and the js are serve up one or the other, not both. Is this correct?</p>
  
  <p>The json gets called if you have an ajax call in your js that got called, and it requests data, and these need data to respond with, right? Do I need it to respond to json and to js, or just one? </p>
  
  <p>If you don't to respond_to, and omit all the types, does it by default respond to html and to js?</p>
  
  <p>When I do respond_to in the controller, rather than a respond_to block within each action, does using <code>respond_with @objects</code> apply to any argument (:thml, :js, :xml, :json, etc)?</p>
  
  <p>Alternate syntax:</p>
  
  <pre><code>class TheController &lt; ApplicationController
  
    respond_to :html, :js, :json, only: [:some_action, :other_action]
  
    def some_action
      respond_with @objects
    end
  end
  </code></pre>
  
  <p>How does the alternate syntax work?</p>
  
  <p>If you use the alternate syntax, can you not respond differently to different types of requests? Do you have to do a respond_to block isntead of the alternate syntax if you want to respond differently? How do each of these cases address graceful degradation to html?</p>