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 mo开发者_C百科del, "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.
You could use a named_scope
So in your user model:
named_scope :whitelist, :conditions => { :awesome => true }
And then in your controller:
User.whitelist
精彩评论