Rails 如果另一个控制器中的条件为假,则控制器列表
Rails Controller list if condition is false in another controller
我在控制器中的 def 有问题
def wait
@evaluations3 = Affiliation.where("go_auth =true") and Affiliation.evaluation.where("ready = false")
我只想显示与这 2 个条件相关的 = true
据我所知,您有一个控制器,其中 index
是一个动作。
在操作中,您有几个模型,您在这些模型上调用 where
查询。
此外,您想要显示对象,其中 Affiliation.where("go_auth =true") and Evaluation.where("ready = false")
在索引操作中。
查看 Active record query interface 的连接。它可能会给你一个方向。
IMO,你必须尝试将你的 Affiliation.where("go_auth =true") || Evaluation.where("ready = false")
推入一个模型/创建一个 PORO 来做同样的事情。这将帮助您在控制器中保持理智。
确实不清楚你要做什么,但是如果情况是这样的:
class Affiliation < ActiveRecord::Base
belongs_to :evaluation
#fields - go_auth: boolean
class Evaluation < ActiveRecord::Base
has_many :affiliations
#fields - ready: boolean
并且您想加载 go_auth 为真且相关评估的就绪字段为真的附属机构,那么我认为这应该可行
@affiliations = Affiliation.include(:evaluation).where(["go_auth = ? and evaluations.ready = ?", true, true])
如果这些不是您的要求,请说出它们是什么。
这解决了我的问题
def wait
@evaluations3 = Evaluation.includes(:affiliation).where("go_auth = true").where("ready = false").references(:affiliation)
结束
我在控制器中的 def 有问题
def wait
@evaluations3 = Affiliation.where("go_auth =true") and Affiliation.evaluation.where("ready = false")
我只想显示与这 2 个条件相关的 = true
据我所知,您有一个控制器,其中 index
是一个动作。
在操作中,您有几个模型,您在这些模型上调用 where
查询。
此外,您想要显示对象,其中 Affiliation.where("go_auth =true") and Evaluation.where("ready = false")
在索引操作中。
查看 Active record query interface 的连接。它可能会给你一个方向。
IMO,你必须尝试将你的 Affiliation.where("go_auth =true") || Evaluation.where("ready = false")
推入一个模型/创建一个 PORO 来做同样的事情。这将帮助您在控制器中保持理智。
确实不清楚你要做什么,但是如果情况是这样的:
class Affiliation < ActiveRecord::Base
belongs_to :evaluation
#fields - go_auth: boolean
class Evaluation < ActiveRecord::Base
has_many :affiliations
#fields - ready: boolean
并且您想加载 go_auth 为真且相关评估的就绪字段为真的附属机构,那么我认为这应该可行
@affiliations = Affiliation.include(:evaluation).where(["go_auth = ? and evaluations.ready = ?", true, true])
如果这些不是您的要求,请说出它们是什么。
这解决了我的问题
def wait
@evaluations3 = Evaluation.includes(:affiliation).where("go_auth = true").where("ready = false").references(:affiliation)
结束