나는 current_user 및 다른 '따라 다니는'사용자의 게시물 모음을 목록에 표시합니다. 포스트는 익명으로 표시 될 수 있습니다. 게시물 이름을 숨 깁니다 (포스트 데이터베이스에 1 또는 0 인 'anon 열'이 있음)조건이있는 배열에서 값을 제외하는 방법
내 컬렉션에 current_user에 대한 익명의 게시물을 표시하고 싶습니다. 다른 사용자의 익명 게시물은 제외합니다.
여기 내 컨트롤러에있는 내용은 다음과 같습니다
@feed = current_user.feed.where('anon != ?', '1')
문제는 내 목록에있는 모든 익명 게시물을 제외입니다.
아이디어가 있으십니까?
갱신 :
def feed
following_other_ids = "SELECT followable_id FROM follows
WHERE followable_type = 'Other' AND follower_id = :user_id"
following_user_ids = "SELECT followable_id FROM follows
WHERE followable_type = 'User' AND follower_id = :user_id"
Post.where("other_id IN (#{following_other_ids})
OR user_id IN (#{following_user_ids})
OR user_id = :user_id", user_id: id)
end
그것은 당신이 만족하는 OR을 사용하는 것이 필요 해요 같은데 여기
내 공급 방법입니다 두 조건 ... http://stackoverflow.com/questions/17192829/does-rails-4-have-support-for-or-queries –그것은 일했다! 감사합니다 힙 : – Jeremy