嵌套表单不显示ActiveAdmin

时间:2016-11-26 01:47:25

标签: ruby-on-rails forms activeadmin

我目前正在使用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

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

1 个答案:

答案 0 :(得分:0)

这就是我所做的事情。

您可以使用for keyword:

获取此类嵌套属性
    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

希望这有用。

相关问题