问题
I'm using Rails 3.0.10 and ActiveAdmin 0.3.2.
I have a problem with nested form and an has_one association. Using an has_many I can get nested forms but I really need to understand and use an has_one in this case.
Model:
class Article < ActiveRecord::Base
belongs_to :section
has_one :seo
accepts_nested_attributes_for :seo
end
class Seo < ActiveRecord::Base
belongs_to :article
end
How write app/admin/article.rb ?
Thanks for any suggestions!
回答1:
I'm having exactly the same problem, and here's what I've got working so far:
f.inputs "Metadata" do
f.inputs :for => [:seo_text, f.object.seo_text || SeoText.new] do |meta_form|
meta_form.input :keywords
meta_form.input :description
end
end
Unfortunately the styling isn't very nice with out-of-the-box ActiveAdmin 0.6.0, so I'm still looking for a better solution. The has_many helper in ActiveAdmin's form build is close - I basically want a has_one
version.
来源:https://stackoverflow.com/questions/7833554/nested-has-one-in-active-admin