gpt4 book ai didi

ruby-on-rails - 如何创建用于查找 Rails 模型记录的黑名单/白名单?

转载 作者:太空宇宙 更新时间:2023-11-03 18:31:19 24 4
gpt4 key购买 nike

我想创建一个模型“白名单”来构建一个我不想在我的主模型“用户”中显示的用户列表。

示例 Controller

def index    @users = User.find(:all) #These are to be filtered behind the scenes in the modelend

示例模型

class User ActiveRecord::Basehas_many :whitelistdef 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

我希望这是有道理的。谢谢您的帮助。

最佳答案

你可以使用 named_scope

所以在你的用户模型中:

named_scope :whitelist, :conditions => { :awesome => true }

然后在你的 Controller 中:

User.whitelist

关于ruby-on-rails - 如何创建用于查找 Rails 模型记录的黑名单/白名单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3661756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com