2016-11-26 73 views
0

我目前使用activeadmin来创建一个嵌套窗体。我可以点击添加嵌套资源按钮,它将显示各个嵌套资源的输入。不过,我希望默认情况下显示输入,而不必点击添加资源按钮(即在表单加载后应该显示输入)。 我对ActiveAdmin文档重新检查了我的代码,并且检查了各种各样的stackoverflow帖子,但无法取得很大进展。嵌套窗体不显示ActiveAdmin的形式

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

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

回答

0

这就是我做的事情。

你可以采取这样的嵌套属性与关键字:

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 

希望这是有帮助的。

+0

感谢您的建议。我实际上没有问题得到保存嵌套的属性。只是无法获取嵌套输入默认显示... – Joshua