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
|
||||
|
||||
def liked?(post)
|
||||
if self.like_for(post)
|
||||
return true
|
||||
if post.likes.loaded?
|
||||
!(like_for(post).nil?)
|
||||
else
|
||||
return false
|
||||
Like.exists?(:author_id => self.person.id, :post_id => post.id)
|
||||
end
|
||||
end
|
||||
|
||||
def like_for(post)
|
||||
if post.likes.loaded?
|
||||
[post.likes, post.dislikes].each do |likes|
|
||||
likes.each do |like|
|
||||
return like if like.author_id == self.person.id
|
||||
likes.detect { |l| l.author_id == self.person.id }
|
||||
end
|
||||
else
|
||||
return Like.where(:post_id => post.id, :author_id => self.person.id).first
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
######### Mailer #######################
|
||||
|
|
|
|||
Loading…
Reference in a new issue