我想创建一个模型,“白名单”来构建我不希望在我的主模型“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
我希望这是有道理的 . 谢谢您的帮助 .
1 回答
你可以使用named_scope
所以在你的用户模型中:
然后在你的控制器中: