title: Rails3 - Sort and Paginate with Kaminari + AJAX + unobtrusive javascript
body: <p>I have successfully set up an ajax pagination with Kaminari.</p>
  
  <p>In order to add a sort feature I followed this great <a href="http://railscasts.com/episodes/240-search-sort-paginate-with-ajax" rel="nofollow noreferrer">Railscast</a> and replaced will_paginate by Kaminari.</p>
  
  <p>The pagination works great but the sort works just the first time because the sort_column and the sort _direction are not updated.</p>
  
  <p>I can't figure out why.</p>
  
  <p>Here is my code :</p>
  
  <p>Controller :</p>
  
  <pre><code>def index
   @questions = Question.order(sort_column + " " +  sort_direction).page(params[:page])
  end
  
  ....
  
  private
  
  def sort_column
   Question.column_names.include?(params[:sort]) ? params[:sort] :  "created_at"
  end
  
  def sort_direction
   %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
  end
  </code></pre>
  
  <p>I have added <code>:remote => true, :method => :get</code> to </p>
  
  <p>ApplicationHelper :</p>
  
  <pre><code>def sortable(title = nil, column)
   title ||= column.titleize
   direction = column == sort_column &amp;&amp; sort_direction == "asc" ? "desc" : "asc"
   link_to title, params.merge(:sort =&gt; column, :direction =&gt; direction), :remote =&gt; true, :method =&gt; :get
  end
  </code></pre>
  
  <p>index.html.erb :</p>
  
  <pre><code>&lt;%= sortable "created_at" %&gt;&lt;br/&gt;
  &lt;div id="questions"&gt;&lt;%= render @questions %&gt;&lt;/div&gt;
  &lt;div id="paginator"&gt;&lt;%= paginate @questions, :remote =&gt; true %&gt;
  </code></pre>
  
  <p>index.js.erb :</p>
  
  <pre><code>$('#questions').html('&lt;%= escape_javascript(render @questions) %&gt;');
  $('#paginator').html('&lt;%= escape_javascript(paginate(@questions, :remote =&gt; true).to_s) %&gt;');
  </code></pre>
  
  <p>Is this a problem with the <code>:remote => true, :method => :get</code> part ? If I remove it the sort works but without ajax.</p>