【问题标题】:Nested Form does not Display form for ActiveAdmin嵌套表单不显示 ActiveAdmin 的表单
【发布时间】:2016-11-26 01:47:25
【问题描述】:

我目前正在使用 activeadmin 创建嵌套表单。我可以单击添加嵌套资源按钮,该按钮将显示相应嵌套资源的输入。但是,我希望默认显示输入,而不必单击添加资源按钮(即,一旦加载表单,就应该显示输入)。 我已经根据 ActiveAdmin 文档重新检查了我的代码,还检查了各种 stackoverflow 帖子,但没有取得太大进展。

Picture of how the form current looks like

我的代码在admin/project.rb中如下:

form title: 'Create a New Project' do |f|
    f.inputs 'Basic Information' do
      f.input :category
      f.input :name
      f.input :location
      f.input :size, sortable: :size do |project|
        "#{project.size}m2"
      end
      f.input :published? 
      f.has_many :project_main_image, heading: 'Project main image', allow_destroy: true, new_record: false do |a|
        a.input :photo, hint: image_tag(a.object.photo.thumb.url, class: 'active-admin-thumbnail')
        a.input :orientation
      end
      f.has_many :project_descriptions, allow_destroy: true do |a|
        a.input :contents, as: :ckeditor, input_html: { ckeditor: { toolbar: 'Full' } }
      end
      f.has_many :project_gallery_images, allow_destroy: true do |a|
        a.input :photo, hint: image_tag(a.object.photo.thumb.url, class: 'active-admin-thumbnail')
        a.input :orientation
        a.input :row_order
      end
      f.actions
    end
  end

任何反馈或建议。如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: ruby-on-rails forms activeadmin


    【解决方案1】:

    我就是这么做的。

    您可以使用 for 关键字获取这样的嵌套属性:

        form do |f|
      f.inputs do
        f.input :user, input_html: { disabled: true }
          f.input :name
          f.input :address
          f.input :city
          f.input :country, as: :string
        end
        f.buttons
    
        f.inputs "Account Information", for: [:account, f.object.account] do |s|
          s.input :active, as: :boolean
          s.input :subscription, as: :boolean
          s.input :expires_on, as: :datepicker
    
          s.actions
        end
      end
    
      controller do
        def permitted_params
          params.permit!
        end
      end
    end
    

    希望这有帮助。

    【讨论】:

    • 感谢您的建议。实际上,我在保存嵌套属性方面没有问题。只是无法默认显示嵌套输入...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-17
    • 1970-01-01
    • 2016-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多