Skip to content

Instantly share code, notes, and snippets.

@emskaplann
Created October 28, 2019 21:23
Show Gist options
  • Save emskaplann/a11f4a92e4aa013576682818e62fa5ae to your computer and use it in GitHub Desktop.
Save emskaplann/a11f4a92e4aa013576682818e62fa5ae to your computer and use it in GitHub Desktop.
<% if current_user %>
<%= form_with model: @like, url: create_like_path, class: "float-right", remote: true do |f| %>
<%= f.hidden_field :user_id, value: session[:user_id] %>
<%= f.hidden_field :post_id, value: post.id %>
<% if User.find(session[:user_id]).liked(post) %>
<a class="limg<%=post.id%>" data-method="delete" data-remote="true" value="<%=post.id%>" href=<%=destroy_like_path(User.find(session[:user_id]).liked_post(post))%>><img class="limg<%=post.id%>" src="images/liked.png"></a>
<% else %>
<%= f.submit "", :type => :image, :src => "images/upvote2.png", :class => "limg#{post.id} float-right" %>
<% end %>
<h6 class="like-class<%=post.id%> float-right" style="vertical-align: bottom;"> <%= post.likes.count %> <span class="pl-3 float-right"></span></h6>
<% end %>
<% else %>
<h6 class="like-class<%=post.id%> float-right" style="vertical-align: bottom;"> <%= post.likes.count %> <span class="pl-3 float-right"></span></h6>
<a class="float-right" href="/login"><img src="images/upvote2.png"></a>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment