fixed unlike the right way
This commit is contained in:
parent
7b864dd208
commit
cd887e9373
3 changed files with 12 additions and 4 deletions
|
|
@ -32,7 +32,7 @@ class LikesController < ApplicationController
|
|||
end
|
||||
|
||||
def destroy
|
||||
if @like = Like.where(:post_id => params[:post_id], :author_id => current_user.person.id).first
|
||||
if @like = Like.where(:id => params[:id], :author_id => current_user.person.id).first
|
||||
current_user.retract(@like)
|
||||
else
|
||||
respond_to do |format|
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ module LikesHelper
|
|||
|
||||
def like_action(post, current_user=current_user)
|
||||
if current_user.liked?(post)
|
||||
link_to t('shared.stream_element.unlike'), like_path(:post_id => post.id, :id => 'xxx'), :method => :delete, :class => 'unlike', :remote => true
|
||||
link_to t('shared.stream_element.unlike'), like_path(current_user.like_for(post)), :method => :delete, :class => 'unlike', :remote => true
|
||||
else
|
||||
link_to t('shared.stream_element.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => 'like', :remote => true
|
||||
end
|
||||
|
|
|
|||
|
|
@ -188,12 +188,20 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def liked?(post)
|
||||
if self.like_for(post)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def like_for(post)
|
||||
[post.likes, post.dislikes].each do |likes|
|
||||
likes.each do |like|
|
||||
return true if like.author_id == self.person.id
|
||||
return like if like.author_id == self.person.id
|
||||
end
|
||||
end
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
|
||||
######### Mailer #######################
|
||||
|
|
|
|||
Loading…
Reference in a new issue