我有以下情况:user
有多个assets
,每个asset
都有一个asset_detail
记录。
楷模:
class User < ActiveRecord::Base
has_many :assets
end
class Asset < ActiveRecord::Base
has_one :asset_detail
belongs_to :user
accepts_nested_attributes_for :asset_detail,
:allow_destroy => false
attr_accessible # ...
end
class AssetDetail < ActiveRecord::Base
belongs_to :asset
attr_accessible # ...
end
控制器动作:
def edit
@user = current_user
@assets = Asset.all
end
def update
@user = current_user
@user.update_attributes(params["user"])
end
看法:
= form_for @user, url: 'update action url' do |f|
= f.fields_for :assets do |ff|
= ff.text_field :title
= ff.fields_for :asset_detail do |fff|
= fff.text_field :value
问题是所有表单字段都已正确填充,但我无法保存它们。表单发送没有任何错误,但数据没有更新。