开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜