title: Rails 4 PUT link auto refresh with ajax
body: <p>In my current controller I have a method that updates the model link with 1 point:</p>
  
  <pre><code>def modify_points
    @link = Link.find(params[:id])
    @link.points += 1
  
  
    respond_to do |format|
      if @link.update_attributes(params[:points])
        format.html { redirect_to root_path }
        format.js
      else
     format.js
      end
    end
  end
  </code></pre>
  
  <p>In my routes:</p>
  
  <pre><code>put 'links/:id/vote' =&gt; 'links#modify_points', :as =&gt; 'modify_points'
  </code></pre>
  
  <p>And my view:</p>
  
  <pre><code>&lt;%= link_to 'Vote', modify_points_path(link), :remote =&gt; true, :method =&gt; :put, :id =&gt; "modify_points" %&gt;
  </code></pre>
  
  <p>But whenever I press the link, I can only see updated information after refreshing the page.</p>
  
  <p>EDIT:
  I created an index.js.erb file in the links view folder directory with the following:</p>
  
  <pre><code>$('#modify_points').update("&lt;%= escape_javascript(render(@link)) %&gt;");
  </code></pre>
  
  <p>Im getting this error in the console when link is pressed:</p>
  
  <pre><code>PUT http://localhost:3000/links/1/vote 500 (Internal Server Error) jquery.js?body=1:8707
  send jquery.js?body=1:8707
  jQuery.extend.ajax jquery.js?body=1:8137
  $.rails.rails.ajax jquery_ujs.js?body=1:74
  $.rails.rails.handleRemote jquery_ujs.js?body=1:150
  (anonymous function) jquery_ujs.js?body=1:300
  jQuery.event.dispatch jquery.js?body=1:5096
  elemData.handle
  </code></pre>