0

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 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

doesn't work, and even if it did, location is a has_one relationship so I don't think it would be applicable
0

You can try by creating location object,

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.