我在Raisl 4 / ActiveAdmin应用程序中有两个模型/资源。
class AdminUser < ActiveRecord::Base
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
has_one :photographer
end
class Photographer < ActiveRecord::Base
belongs_to :admin_user, dependent: :destroy
accepts_nested_attributes_for :admin_user
end
ActiveAdmin.register Photographer do
permit_params :code, :nickname, :profile, :facebook_url, :twitter_url, :instagram_url, :address, :complement, :zip_code, :city, :state, :country,
:phone, :cellphone, :commission, :withhold_tax, :bank_number, :bank_branch_number, :bank_account_number, :identity_document_number,
:rfb_document_number, admin_user_attributes: [:email, :password, :password_confirmation]
form do |f|
f.inputs for: [:admin_user, (f.object.admin_user || f.object.build_admin_user)] do |auf|
auf.input :email
auf.input :password
auf.input :password_confirmation
end
f.inputs do
f.input :code
f.input :nickname
f.input :profile
f.input :facebook_url
f.input :twitter_url
f.input :instagram_url
f.input :address
f.input :complement
f.input :zip_code
f.input :city
f.input :state
f.input :country, as: :string
f.input :phone
f.input :cellphone
f.input :commission
f.input :withhold_tax
f.input :bank_number
f.input :bank_branch_number
f.input :bank_account_number
f.input :identity_document_number
f.input :rfb_document_number
end
f.actions
end
end
创建/验证过程完美无缺,但是,在编辑摄影师而不更改电子邮件时,我收到错误“电子邮件已被拍摄”,因为实际关联的AdminUser记录正在创建而未被编辑。
答案 0 :(得分:0)
我发现了问题。要正确编辑工作,您还必须接受用户属性中的Id参数,否则它将尝试创建一个新参数。
admin_user_attributes: [:id, :email, :password, :password_confirmation]
非常感谢@ d34n5。
Strong parameters for nested attributes returns "unpermitted parameters" when empty array