我想从一个方法红宝石真如果每个职位跟随一个人和假如果不。方法红宝石返回真或假
我有这样的方法:
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
我没有测试过,但你也能够使用'break'上紧接在'value = false'后面的行,以防止额外循环 – SimonMayer 2012-01-29 13:13:41
对于你的carma,我接受你的回应。它确实工作正常:D。非常感谢你。 – hyperrjas 2012-01-29 14:02:18