title: Using the respond_to method to render a js.erb partial
body: <p>I have a feature where users like/unlike and dislike/undislike dishes. This is how I initially have my actions setup:</p>
  
  <p><strong>Dishes Controller</strong></p>
  
  <pre><code>class DishesController &lt; ApplicationController
    def like
      @dish.liked_by current_user
    end
  
    def dislike
      @dish.disliked_by current_user
    end
    ...
  end
  </code></pre>
  
  <p>Considering the <code>js.erb</code> templates for each template are completely identical I wanted to create just one shared partial that each could use:</p>
  
  <p><strong>Original Setup</strong></p>
  
  <pre><code># like.js.erb, unlike.js.erb,dislike.js.erb,undislike.js.erb
  
  $(".restaurant__dish-vote--&lt;%= @dish.modifier_class %&gt;").html('&lt;%= escape_javascript(render "restaurants/menu_partials/dish_votes", dish: @dish) %&gt;');
  </code></pre>
  
  <p><strong>New Setup</strong></p>
  
  <pre><code># shared/_vote.js.erb
  
  $(".restaurant__dish-vote--&lt;%= @dish.modifier_class %&gt;").html('&lt;%= escape_javascript(render "restaurants/menu_partials/dish_votes", dish: @dish) %&gt;');
  </code></pre>
  
  <p>Now I'm trying to refactor my controller to reflect these changes but the ajax functionality doesn't seem to work with the following:</p>
  
  <pre><code>class DishesController &lt; ApplicationController
    def like
      respond_to do |format|
        format.js { render partial: "dishes/shared/vote.js.erb" }
      end
  
      @dish.liked_by current_user
    end
  end
  </code></pre>
  
  <p>The action completes but the changes on the user-facing side are only reflected upon refresh. What am I doing wrong?</p>