Ruby on rails 4 Active Admin有许多表单在选项卡中使用同一模型两次

Ruby on rails 4 Active Admin有许多表单在选项卡中使用同一模型两次,ruby-on-rails-4,activeadmin,has-many,nested-form-for,Ruby On Rails 4,Activeadmin,Has Many,Nested Form For,我有这个PostApplication模型,PostApplication在下面的activeadmin资源中有很多文档,其中包含很多表单 我想显示基于布尔值的文档模型的各种记录。我只想通过postapplication model在不同的选项卡中创建文档,但在第二个选项卡中,每当我上传新文件时,它都会更新上一个现有文档 请帮忙 ActiveAdmin.register PostApplication do form do |f| tab "Documents" do tabs do

我有这个PostApplication模型,PostApplication在下面的activeadmin资源中有很多文档,其中包含很多表单

我想显示基于布尔值的文档模型的各种记录。我只想通过postapplication model在不同的选项卡中创建文档,但在第二个选项卡中,每当我上传新文件时,它都会更新上一个现有文档

请帮忙

ActiveAdmin.register PostApplication do
form do |f|
  tab "Documents" do
    tabs do
      tab "Not Scanned" do
        f.has_many :documents, for: [:documents, f.object.documents.where(is_scanned: false) || Document.new(is_scanned: false)] do |la|
        la.semantic_errors *la.object.errors.keys
        la.input :verified
        la.input :document, as: :file, required: false, :hint => (la.object.new_record? || !la.object.document.exists? ? "" : link_to("Download", "#"))
        la.input :_destroy, as: :boolean, required: false, label: t('remove')
      end
    end

    tab "Scanned" do
      f.has_many :documents, for: [:documents, f.object.documents.where(is_scanned: true) || Document.new(is_scanned: true)] do |la|
        la.semantic_errors *la.object.errors.keys
        la.input :verified
        la.input :document, as: :file, required: false, :hint => (la.object.new_record? || !la.object.document.exists? ? "" : link_to("Download","#"))
        la.input :_destroy, as: :boolean, required: false, label: t('remove')
      end
    end
   end
  end
end
end

您可以为扫描和未扫描的文档创建不同的关联。比如说,
扫描了很多:文档
扫描了很多:文档
。不过,您需要在此处传递所需的选项。因为扫描和未扫描的文档都由相同的列组成,并且它们仅由一个布尔值分隔,而布尔值是经过扫描的,因此不需要创建两个模型,使用它的可能方式是什么?您不需要为这些关联创建不同的模型。使用
has\u many
定义关联时,您只需传递条件
is\u scanned:true
is\u scanned:false
。见此: