Document liked? and like_for
This commit is contained in:
parent
e4476702d4
commit
10f5d658b2
1 changed files with 5 additions and 0 deletions
|
|
@ -170,6 +170,8 @@ class User < ActiveRecord::Base
|
||||||
build_relayable(Like, options)
|
build_relayable(Like, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check whether the user has liked a post. Extremely inefficient if the post's likes are not loaded.
|
||||||
|
# @param [Post] post
|
||||||
def liked?(post)
|
def liked?(post)
|
||||||
if self.like_for(post)
|
if self.like_for(post)
|
||||||
return true
|
return true
|
||||||
|
|
@ -178,6 +180,9 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Get the user's like of a post, if there is one. Extremely inefficient if the post's likes are not loaded.
|
||||||
|
# @param [Post] post
|
||||||
|
# @return [Like]
|
||||||
def like_for(post)
|
def like_for(post)
|
||||||
[post.likes, post.dislikes].each do |likes|
|
[post.likes, post.dislikes].each do |likes|
|
||||||
likes.each do |like|
|
likes.each do |like|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue