title: Rails detect if request was AJAX
body: <p>In my action I wish to only respond with processing if it was called from an AJAX request. How do I check?</p>
  
  <p>I want to do something like this:</p>
  
  <pre><code>def action
     @model = Model.find(params[:id])
  
     respond_to do |format|
  
        if (wasAJAXRequest()) #How do I do this?
  
           format.html #action.html.erb
  
        else
  
           format.html {redirect_to root_url}
     end
  end
  </code></pre>