title: Rails View not updating after jQuery Ajax call
body: <p>I'm in the middle of my first rails project, and have reached the stage where I want to change the <code>ORDER BY</code> of my models' index depending on the value of a <code>SELECT</code> tag.</p>
  
  <p>I have the following onchange in my index.html.erb</p>
  
  <pre><code>&lt;div id="sortBy"&gt;
          &lt;span&gt;Sort by:&lt;/span&gt;
          &lt;%= select_tag "sort_by", options_for_select([ "Newest first", "Oldest first" ], "Newest first"), { :onchange =&gt; "changeSortOrderJs(this.value)" } %&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>That should update this:</p>
  
  <pre><code>&lt;% @horses.each do | horse | %&gt;
     &lt;%= horse.name %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This calls the following method in my coffeescript asset ( prefixed with @ since it is an anon function):</p>
  
  <pre><code>@changeSortOrderJs = (val) -&gt;
    $.ajax
      type: 'GET'
      url: '/horses'
      data: order: val
  </code></pre>
  
  <p>This maps to my index action in the HorsesController</p>
  
  <pre><code>def index
          order = params[:order]
  
          if(order == nil) 
              order = 'Newest first'
          end
  
          @horses = Array.new
  
          if order == 'Newest first'
  
              @horses = Horse.all.order("created_at DESC")
  
          elsif order == 'Oldest first'
  
              @horses = Horse.all.order("created_at ASC")
          end
  
          //tried this later but didn't work either
          respond_to do |format|
              format.html
          end
      end
  </code></pre>
  
  <p>I can see in my development.log that is working and the @horses are being populated in their correct order.  But the view does not refresh.</p>
  
  <p>If I use <code>respond_with(@horses)</code> and then a success callback in the ajax call, i.e.</p>
  
  <pre><code>@changeSortOrderJs = (val) -&gt;
    $.ajax
      type: 'GET'
      url: '/horses'
      data: order: val
      success: (result) -&gt;
        $('body').html(result)
  </code></pre>
  
  <p>then it does work and the horses get reordered.  But I would rather not replace the whole body this way.</p>
  
  <p>I thought the whole point with instance variables was that you could redefine them and the view would update automatically?</p>