Active Admin有很多表单在选项卡中两次使用相同的模型

时间:2017-04-08 17:49:58

标签: ruby-on-rails-4 activeadmin has-many nested-form-for

我在下面的activeadmin资源中有这个PostApplication Model和PostApplication has_many Documents,其中包含has_many表单。

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

请帮助

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

0 个答案:

没有答案