title: jQuery Ajax calls in Rails 3 getting 401 Unauthorized Request
body: <p>I have a Rails 3.1 application that uses devise for authentication. I am trying to make a call via ajax to a url. For some reason I keep getting 401 Unauthorized access. I have followed the tutorial here <a href="http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery" rel="nofollow">http://henrik.nyh.se/2008/05/rails-authenticity-token-with-jquery</a> on how to authenticate jQuery requests. The code for the request is </p>
  
  <pre><code>        $.get('/chromosomes.json', {sequence_start: '10', sequence_end: '100'},
          function(data){
                          alert(data)
         }, 'json');
  </code></pre>
  
  <p>What is strange is that on the server I see</p>
  
  <p>Started GET "/chromosomes.json?sequence_start=10&amp;sequence_end=100&amp;_=1320958293654" for 127.0.0.1 at Thu Nov 10 15:51:33 -0500 2011
    Processing by ChromosomesController#index as JSON
    Parameters: {"sequence_start"=>"10", "_"=>"1320958293654", "sequence_end"=>"100"}
  Completed   in 10ms</p>
  
  <p>In my controller I have:</p>
  
  <pre><code>before_filter :authenticate_user!
  
  def index
  
          respond_to do |format|
        format.html
        format.json  { render :json =&gt; @chromosomes }
      end
  end
  </code></pre>
  
  <p>For some reason the authenticity session token is not being passed to Rails. If I remove the authenticate_user! before filter it works fine!? Any help is very much appreciated. Thanks!</p>