fixed unlike the right way

This commit is contained in:
MrZYX 2011-05-29 18:15:46 +02:00
parent 7b864dd208
commit cd887e9373
3 changed files with 12 additions and 4 deletions

View file

@ -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|

View file

@ -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

View file

@ -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 #######################