Without loaded? I was confused by the liked? and like_for methods.
This commit is contained in:
parent
480d7c47cf
commit
2103d54fe4
1 changed files with 8 additions and 7 deletions
|
|
@ -171,20 +171,21 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def liked?(post)
|
def liked?(post)
|
||||||
if self.like_for(post)
|
if post.likes.loaded?
|
||||||
return true
|
!(like_for(post).nil?)
|
||||||
else
|
else
|
||||||
return false
|
Like.exists?(:author_id => self.person.id, :post_id => post.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def like_for(post)
|
def like_for(post)
|
||||||
[post.likes, post.dislikes].each do |likes|
|
if post.likes.loaded?
|
||||||
likes.each do |like|
|
[post.likes, post.dislikes].each do |likes|
|
||||||
return like if like.author_id == self.person.id
|
likes.detect { |l| l.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