[英]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". 我想创建一个模型“ Whitelist”,以建立一个我不想显示在主模型“ 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 您可以使用named_scope
So in your user model: 因此,在您的用户模型中:
named_scope :whitelist, :conditions => { :awesome => true }
And then in your controller: 然后在您的控制器中:
User.whitelist
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.