【发布时间】:2012-02-21 15:04:11
【问题描述】:
如果每个帖子都被一个人关注,我想从方法 ruby true 中获取,如果 不是,则为 false。
我有这个方法:
def number_of_posts_that_are_followed
user_to_be_followed = User.find(params[:id]) #users whose posts, will be followed by another user
user_to_be_followed.posts.each do |this_post|
if current_user.follows?(this_board) == true #method that returns true if the current_user is following this post of the user whose posts will be followed
return true
else
return false
end
end
end
问题在于,如果第一个帖子(在第一次迭代中)紧随其后的是 current_user,则此方法返回 true。如果每个帖子都被关注,我想返回 true,如果没有被关注,我想返回 false。
我试过这样计数:
count = user_to_be_followed.posts.count
【问题讨论】:
标签: ruby count block each ruby-1.9.2