title: Rails: How does the respond_to block work?
body: <p>I'm going through the <a href="http://guides.rubyonrails.org/getting_started.html" rel="noreferrer">Getting Started with Rails</a> guide and got confused with section 6.7. After generating a scaffold I find the following auto-generated block in my controller:</p>
  
  <pre><code>def index
    @posts = Post.all
  
    respond_to do |format|
      format.html  # index.html.erb
      format.json  { render :json =&gt; @posts }
    end
  end
  </code></pre>
  
  <p>I'd like to understand how the respond_to block actually works. What type of variable is format? Are .html and .json methods of the format object? The <a href="http://api.rubyonrails.org/" rel="noreferrer">documentation</a> for </p>
  
  <p><code>ActionController::MimeResponds::ClassMethods::respond_to</code> </p>
  
  <p>doesn't answer the question.</p>