[英]Rails Admin: Remove associated records option
I am implementing Rails Admin on my app and i would like to remove the option of seeing associated records.我正在我的应用程序上实施 Rails Admin,我想删除查看相关记录的选项。 What i want to do is keep the option of adding a new record but not selecting a pre-existing one.我想要做的是保留添加新记录的选项,但不选择预先存在的记录。 The screen shot below shows what i am talking about:下面的屏幕截图显示了我在说什么:
I want to keep the product_variants field but with the only option of the button "Add new product variant"我想保留 product_variants 字段,但只有“添加新产品变体”按钮的选项
Thanks !谢谢 !
There's no built in way to do that.没有内置的方法可以做到这一点。 What i've done in the past is hide all records that are not associated.我过去所做的是隐藏所有不相关的记录。
class Product < ApplicationRecord
rails_admin do
edit do
field :product_variants do
associated_collection_scope do
inline_edit false
associated_collection_scope do
product = bindings[:object]
proc { |scope| scope.where(product: product) }
end
end
end
end
end
end
I'm guessing the associations of course, but that should point you in the right direction.我当然在猜测这些关联,但这应该为您指明正确的方向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.