在活动管理员中嵌套has_one [英] nested has_one in active admin

查看:58
本文介绍了在活动管理员中嵌套has_one的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails 3.0.10和ActiveAdmin 0.3.2.

I'm using Rails 3.0.10 and ActiveAdmin 0.3.2.

我对嵌套表单和has_one关联有疑问.使用has_many可以嵌套表格,但是在这种情况下,我确实需要理解和使用has_one.

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.

型号:

class Article < ActiveRecord::Base
  belongs_to :section
  has_one :seo
  accepts_nested_attributes_for :seo
end

class Seo < ActiveRecord::Base
  belongs_to :article
end

如何编写app/admin/article.rb?

How write app/admin/article.rb ?

谢谢您的建议!

推荐答案

我遇到了完全相同的问题,这是到目前为止我正在努力的事情:

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

不幸的是,现成的ActiveAdmin 0.6.0的样式不是很好,因此我仍在寻找更好的解决方案. ActiveAdmin表单构建中的 has_many helper 已关闭-我基本上想要一个has_one版本.

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.

这篇关于在活动管理员中嵌套has_one的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆