我尝试确定关联的范围,以便用户在编辑关系时看不到已发送的提醒。但是,我希望它们在“显示” View 中显示,而不是在“编辑” View 中显示。
我无法让范围在每个领域工作。我可以使用 proc 来确定整个 has_many 调用的范围,但这不会让我在“显示”页面上显示结果,因为它是模型范围的。这是我当前的代码,基于 RailsAdmin wiki,它似乎不起作用:
group :reminders do
label 'Reminders'
field :reminders do
active true
associated_collection_scope do
Proc.new { |scope|
scope = scope.where(sent: false)
}
end
end
end
最佳答案
也许尝试将上面的代码扔到 edit do ; end
中堵塞。所以,会变成:
edit do
group :reminders do
label 'Reminders'
field :reminders do
active true
associated_collection_scope do
Proc.new { |scope|
scope = scope.where(sent: false)
}
end
end
end
end
关于ruby-on-rails - RailsAdmin 中的范围关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16222136/