nested has_one in active admin

风流意气都作罢 提交于 2019-12-10 17:46:28

问题


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

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