I'm still a newb w/r/t rails and ruby, so this may be obvious, but I
havent found an answer in my searching yet...
I have a visibility attribute on a Story model that says some of the
objects can only be seen by "friends" and some just by "family".
I also have a Contacts model where each object has an attribute to
mark them as a Friend or Family for a given User.
My User model hasMany Stories and hasMany Contacts.
Maybe you see where this is going...
When a user is logged in, I want to show them only the Stories that
should be visible to them as determined by one of the following two
a) the Story is only visible to Friends and the user is in the Story
owner's Friends list
b) the Story is only visible to Family and the user is in the Story
owner's Family list
What I'm looking for is the best way to do this by doing it "the Rails
Way" and being as efficient as possible.
I was starting to approach it like this:
1) get the list of users for which the current user is in their
2) get the list of users for which the current user is in their Family
3) find and show Stories where visibility = Story::VISIBLITY_FRIENDS
and current_user is in list 1 OR where visibility =
Story::VISIBLITY_FAMILY and current_user is in list 2
...but this seems clumsy and maybe a performance hog... also I'm not
sure yet how to do a SQL IN clause in Rails.
Anyone have suggestions for a better approach?
And could someone show me how to do that IN clause in a find method
(I've searched and haven't found it yet)? Guess I could do a
Thanks in advance.