I want to stop following a user if and only if I have left to follow all his posts.
For this I have tried with this method but does not works for me.
user_with_posts = User.find(params[:id])
posts_of_users = user_with_posts.posts
posts_of_users.each do |post|
current_user.unfollow(user_with_posts) unless current_user.follows?(post)
end
The problem here is that if user_with_post have 3 posts and current_user only follow 1 post the code run the current_user.unfollow(user_with_posts)
I want only run the **current_user.unfollow(user_with_posts) if and only if I have left to follow all the post for user_with_posts
You can use Enumerable#any? for this purpose: