我想创建一个模型“Whitelist”来构建我不希望在我的主模型“User”中显示的用户列表。
示例控制器
def index @users = User.find(:all) #These are to be filtered behind the scenes in the model end
示例模型
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
我希望这是有道理的。谢谢您的帮助。
答案 0 :(得分:3)
您可以使用named_scope
所以在您的用户模型中:
named_scope :whitelist, :conditions => { :awesome => true }
然后在你的控制器中:
User.whitelist