I am trying to create like button which, allows a user to like a post. Then button transform into an unlike button which, allows a user to unlike a post. I did it, but i think it's wrong.
My code
<div class='likes'>
<% if user_signed_in?%>
<% unless current_user.likes?(post) %>
<%= link_to image_tag('unlike.png', alt: 'unlike'), like_path(post) %>
<% else %>
<%= link_to image_tag('like.png', alt: 'like'), unlike_path(post) %>
<% end %>
<% if post.likers_count >0 %>
<%= post.likers_count %>
<% end %>
<% end %>
</div>
When I click on like button whole page is reloaded, but i need only reload a button. How I can do it?