[英]Rails Admin form for has_many association
是的,您可以像这样定义关联范围
rails_admin do
edit do
field :students do
associated_collection_scope do
class_room = bindings[:object]
proc { |scope| scope.where(class_room: class_room) }
end
end
end
end
您想在表中添加is_active(Boolean)字段以保持学生状态为活动或不活动。 然后使用范围过滤学生。
class Student< ApplicationRecord
scope :active_students, -> { where(is_active: true) }
scope :deactive_students, -> { where(is_active: false) }
end
称为范围
@active_students = Student.active_students
@deactive_students = Student.deactive_students
它有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.