BioDevMike
BioDevMike

Reputation: 315

How do I create a blacklist/whitelist for finding Rails model records?

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.

Upvotes: 1

Views: 1738

Answers (1)

jordinl
jordinl

Reputation: 5239

You could use a named_scope

So in your user model:

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

And then in your controller:

User.whitelist

Upvotes: 3

Related Questions