rails ActiveAdmin nested form has_one accepts_attributes_for formtastic issue

后端 未结 3 1141
清歌不尽
清歌不尽 2020-12-13 14:44

I am using ActiveAdmin and Rails 3.1 -- having problem understanding whether the following is a bug, or if there is some way to do it correctly that I am not understanding.

相关标签:
3条回答
  • 2020-12-13 15:12

    I found a better solution for you. You can use :for option in inputs helper.

    f.inputs "Meta Data", for: [:meta_data, f.object.meta_data || MetaData.new] do |meta_form|
      meta_form.input :title
      meta_form.input :description
      meta_form.input :keywords
    end
    

    I think this might work too, but I didn't check

    f.inputs :title, :desctiption, :keywords, 
      name: "Meta Data",
      for: [:meta_data, f.object.meta_data || MetaData.new]
    
    0 讨论(0)
  • 2020-12-13 15:24

    In rails 4, this is something that works, with a nice design

    e.g., A customer has one account

    model/customer.rb

    accepts_nested_attributes_for :account
    

    admin/customer.rb

    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 讨论(0)
  • 2020-12-13 15:29

    i was having the same problem, i worked in your hack and got it working. i then moved <% @page.build_meta_data %> to a custom new method like this

      controller do
        def new
          @tenant = Tenant.new
          @tenant.build_tenant_configurable
        end
      end
    

    hope this helps

    0 讨论(0)
提交回复
热议问题