Revert "Without loaded? I was confused by the liked? and like_for methods."
This reverts commit 2103d54fe4.
This commit is contained in:
parent
2103d54fe4
commit
b446404348
1 changed files with 7 additions and 8 deletions
|
|
@ -171,21 +171,20 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def liked?(post)
|
def liked?(post)
|
||||||
if post.likes.loaded?
|
if self.like_for(post)
|
||||||
!(like_for(post).nil?)
|
return true
|
||||||
else
|
else
|
||||||
Like.exists?(:author_id => self.person.id, :post_id => post.id)
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def like_for(post)
|
def like_for(post)
|
||||||
if post.likes.loaded?
|
[post.likes, post.dislikes].each do |likes|
|
||||||
[post.likes, post.dislikes].each do |likes|
|
likes.each do |like|
|
||||||
likes.detect { |l| l.author_id == self.person.id }
|
return like if like.author_id == self.person.id
|
||||||
end
|
end
|
||||||
else
|
|
||||||
return Like.where(:post_id => post.id, :author_id => self.person.id).first
|
|
||||||
end
|
end
|
||||||
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
######### Mailer #######################
|
######### Mailer #######################
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue