views:

38

answers:

1

I want to create a model, "Whitelist" to build a list of users that I do not want displayed in my main model, "User".

Example Controller

def index
    @users = User.find(:all) #These are to be filtered behind the scenes in the model
end

Example Model

class User ActiveRecord::Base
has_many :whitelist
def self.find
    #Add something that will lookup items in the Whitelist model and filter those matches out of a find(:all) in the User model.
end

I hope this makes sense. Thanks for the help.

+2  A: 

You could use a named_scope

So in your user model:

named_scope :whitelist, :conditions => { :awesome => true }

And then in your controller:

User.whitelist
jordinl
Your answer has lead me to http://apidock.com/rails/ActiveRecord/NamedScope/ClassMethods/scope which, seems to have a join and a where condition that would work. I think I need to upgrade my rails install to use it but, this looks like it will work. Thanks for the help.
ThomasG33K