rails ActiveAdmin nested form has_one accepts_attributes_for formtastic issue

僤鯓⒐⒋嵵緔 提交于 2019-11-28 19:16:43
Pechkin

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]
vladCovaliov

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
ben.m

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!