I am trying to add a liking functionality to a place object that I have created in rails -- I'm using Actsasvotable and have no issue adding/deleting likes from the database. However, I am now stuck and can't figure out how to add the like without a page load.
Here is my view:
<div class="place-likes" id="place-<%= place.id %>.likes">
<%= render 'places/likes', place: place %>
</div>
Which includes the following partial:
<%= render 'shared/likes_form', likeable: place %>
<div class="place-<%= place.id %>.like-count"><%= likers_of(place) %></div>
Which calls the shared likes form (using for other objects other than places):
<% if current_user.liked? likeable %>
<%= form_tag unlike_path(likeable_type: likeable.class.to_s, likeable_id: likeable.id), method: :post, remote: true, class: 'unlike' do %>
<% button_tag class: "glyphicon glyphicon-heart" do %>
<% end %>
<% end %>
<% else %>
<%= form_tag like_path(likeable_type: likeable.class.to_s, likeable_id: likeable.id), remote: true, class: 'like' do %>
<% button_tag class: "glyphicon glyphicon-heart-empty" do %>
<% end %>
<% end %>
<% end %>
Once the controller saves the like into the database, it returns the following javascript. I have checked closely that this javascript matches the correct object using the console, but I the .html part will not work whatever I do:
$("#<%= @likeable_type.downcase %>-<%= @likeable.id %>.likes").html("<%= j (render partial: 'places/likes', locals: { place: @likeable } ) %>");
Any help here would be greatly appreciated! Thanks!!