mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
Reimplement ajax like/unlike behaviour
This commit is contained in:
18
app/assets/javascripts/posts.js
Normal file
18
app/assets/javascripts/posts.js
Normal file
@@ -0,0 +1,18 @@
|
||||
$(document).ready(function () {
|
||||
$('.post-like').show();
|
||||
|
||||
$('.post-like').on('ajax:success', function(event, data) {
|
||||
var like_control = $('#post-' + data.id + ' .post-like');
|
||||
|
||||
$('#post-' + data.id + ' .like-count').text(data.description);
|
||||
if (data.liked_by_member) {
|
||||
like_control.data("method", "delete");
|
||||
like_control.attr("href", data.url);
|
||||
like_control.text("Unlike");
|
||||
} else {
|
||||
like_control.data("method", "post");
|
||||
like_control.attr("href", '/likes.json?post_id=' + data.id);
|
||||
like_control.text("Like");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -39,8 +39,8 @@
|
||||
= pluralize(post.likes.count, "like") unless post.likes.empty?
|
||||
- if member_signed_in?
|
||||
- if !post.members.include? current_member
|
||||
= link_to 'Like', likes_path(Like.new, post_id: post.id, format: :json), method: :post, remote: true, class: 'post-like', style: "display: none"
|
||||
= link_to 'Like', likes_path(Like.new, post_id: post.id, format: :json), method: :post, remote: true, class: 'post-like'#, style: "display: none"
|
||||
- else
|
||||
- like = post.likes.find_by(member: current_member)
|
||||
- if like
|
||||
= link_to 'Unlike', like_path(like, format: :json), method: :delete, remote: true, class: 'post-like', style: "display: none"
|
||||
= link_to 'Unlike', like_path(like, format: :json), method: :delete, remote: true, class: 'post-like'#, style: "display: none"
|
||||
|
||||
Reference in New Issue
Block a user