루비 메소드에서 얻으려는 경우 true 사람마다 모든 게시물을 따르는 경우 이 아닌 경우이면 false입니다.메소드 루비가 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를 반환한다는 것입니다 :
나는이 방법을 가지고있다. 나는 모든 게시물을 따르거나, 그렇지 않은 경우 false를 되찾기를 원합니다. 내가 시도
이 같은 수를 넣어 :
count = user_to_be_followed.posts.count
내가 테스트하지 않은 (즉. 컬렉션 구성원 중 어느 것도 허위 또는 전무없는 경우에만 true를 돌려줍니다? 전부입니다)하지만 당신은 또한에 break''사용할 수 있습니다 여분의 루핑을 막기 위해'value = false' 바로 뒤에 오는 줄 – SimonMayer
당신의 카마를 위해, 나는 당신의 반응을 받아들입니다. 그것은 잘 작동합니다 : D 조. 고맙습니다. – hyperrjas