title: Rails Acts_as_votable Gem Like/Unlike Buttons with Ajax
body: <p>I'm new to Ruby On Rails, I used the acts_as_votable gem to create Like and Unlike Buttons to make Users like and unlike Posts but I can't make them change from Like to Unlike (and viceversa) and update the counter each time they click without refreshing the page. I tried following other kind-of-similar answers but I had no luck.
  Without the messy changes I tried to do to implement Ajax my code looked like this:</p>
  
  <p>Post Model acts_as_votable and User Model acts_as voter</p>
  
  <p>Posts Controller has</p>
  
  <pre><code>def like
    @post = Post.find(params[:id])
    @post.liked_by current_user
    redirect_to :back
  end
  
  def unlike
    @post = Post.find(params[:id])
    @post.unliked_by current_user
    redirect_to :back
  end
  </code></pre>
  
  <p>Routes have</p>
  
  <pre><code>resources :posts do
    member do
      put 'like', to: "posts#like"
      put 'unlike', to: "posts#unlike"
    end
  end
  </code></pre>
  
  <p>View has</p>
  
  <pre><code>&lt;%= @post.get_likes.size%&gt;
    &lt;% if @post.get_likes.size ==1 %&gt;
      person like this
    &lt;% else %&gt;
     people like this
  &lt;% end %&gt;
  
  
  &lt;div class="btn-group"&gt;
  
    &lt;% if (current_user.liked? @post) %&gt;
      &lt;%= link_to unlike_post_path(@post), method: :put, class: "btn btn-default btn-sm" do %&gt;
      &lt;span class="glyphicon glyphicon-chevron-down"&gt;&lt;/span&gt;
        Unlike
      &lt;%end %&gt;
  
    &lt;% else %&gt;
  
      &lt;%= link_to like_post_path(@post), method: :put, class: "btn btn-primary btn-sm" do %&gt;
      &lt;span class="glyphicon glyphicon-chevron-up"&gt;&lt;/span&gt;
        Like
      &lt;% end %&gt;
    &lt;% end %&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I read a lot of answers about Ajax but I was unable to replicate the results.
  Thank you in advance! </p>