0
votes

Been trying to figure out why my form won't work properly. -- this is the closest I get to getting it working, it shows the location field when I do this however when I submit form it says "Unknown attribute locations", which I believe is because locations should actually be accessed like f.inputs :name => "Location", :for => :location do | location_form|, instead of what I have below (right?) but when I do it non plural nothing shows up at all. If i do it plural, it doesen't know what to do with the location attributes. Can anyone tell me if I am doing something wrong, or if this is a bug? Thanks a ton in advance.

class Store < ActiveRecord::Base

  has_one :location
  belongs_to :admin_user
  accepts_nested_attributes_for :location

end

class Location < ActiveRecord::Base

  belongs_to :store

end

ActiveAdmin.register Store do

  form do |f|
    f.inputs "Details" do
      f.input :name
      f.input :description
      f.input :admin_user
    end

    f.inputs :name => "Location", :for => :locations do |location_form|
      location_form.input :address
    end

    f.buttons
  end
end 
3

3 Answers

4
votes

Perhaps try instead of

f.inputs :name => "Location", :for => :locations do |location_form|
  location_form.input :address
end

this

f.inputs :name => "Location", :for => [f.object.location || Location.new] do |location_form|
  location_form.input :address
end
3
votes

You should try the has_many method of the form builder object active admin gives you.

f.has_many :locations do |location_form|
  location_form.input :name
end
0
votes

You can try by creating location object,

f.semantic_fields_for :locations, Location.new do |ff|
  ff.input :name
end