1

I have a collection of posts from current_user and other 'followed' users displayed in a list. Posts can be marked anonymous on submit which hides the posters name (there is an 'anon column in the posts database that is either 1 or 0')

In my collection of posts, I want to show anonymous posts for the current_user, but exclude the anonymous posts from other users.

Here's what I have in my controller:

@feed = current_user.feed.where('anon != ?', '1')

The problem is it excludes all anonymous posts in my list.

Any ideas?

update:

Here is my feed method:

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
Jeremy
  • 21
  • 6

2 Answers2

1
@feed = current_user.feed.where('anon != ? OR user_id = ?', '1', current_user)
Jeremy
  • 21
  • 6
0

What about:

@feed = current_user.posts.where(anon: 0)
Tan Nguyen
  • 3,281
  • 1
  • 18
  • 18
  • 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path. – Jeremy Jun 23 '16 at 04:12
  • it's View error, another line of code, not error from this line of code man – Tan Nguyen Jun 23 '16 at 04:21
  • Sorry, I changed another bit of code while trying things and forgot to fix it before trying your solution. Your solution displays all 'anon' posts. But I want to display all posts except 'anon posts' from other users. – Jeremy Jun 23 '16 at 04:40
  • Edited. Just change it from 1 to 0 – Tan Nguyen Jun 23 '16 at 04:44