我想從一個方法紅寶石真如果每個職位跟隨一個人和假如果不。方法紅寶石返回真或假
我有這樣的方法:
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