如何在activeadmin上显示嵌套记录?

时间:2013-11-07 15:43:55

标签: ruby-on-rails activeadmin

到目前为止,我有两个模型,用户和个人资料

Class User < ActiveRecord::Base
  has_one :profile
  accepts_nested_attributes_for :profile

Class Profile < ActiveRecord::Base
  belongs_to :user

在我的有效管理模式

form  do |f|
  f.inputs "User" do
    f.input :email
    #code to get the profile data
  end
  f.action :submit
end

所以我想在用户表单上获取配置文件数据我尝试了几件事,但我无法得到它们。

1 个答案:

答案 0 :(得分:0)

这样的东西
f.inputs 'Profile', :for => [:profile, f.object.profile || Profile.new] do |profile_form|
  profile_form.input ...
  ...
end
f.inputs“User”块内的

应该可以正常工作。只需使用profile_form在此块中设置Profile的属性。