Ruby on rails Rails 4.0:保存有一个关联不起作用
我有一个简单模型的rails应用程序: 客户只有一个地址 地址属于客户 new.html.erbRuby on rails Rails 4.0:保存有一个关联不起作用,ruby-on-rails,model,associations,has-one,Ruby On Rails,Model,Associations,Has One,我有一个简单模型的rails应用程序: 客户只有一个地址 地址属于客户 new.html.erb 您的客户模型中缺少地址的接受嵌套属性 它应该是这样的,告诉rails您的代码实际上正在更新其他模型 class Customer < ActiveRecord::Base has_one :address accepts_nested_attributes_for :address end class客户rake db:migrate??,我没有异常…@Geo
您的客户模型中缺少地址的接受嵌套属性
它应该是这样的,告诉rails您的代码实际上正在更新其他模型
class Customer < ActiveRecord::Base
has_one :address
accepts_nested_attributes_for :address
end
class客户
希望这能有所帮助。您是否在您的模型中使用接受
的嵌套属性?运行@customer.save代码>什么是异常?不,我不使用accepts\u nested\u attributes\u for:/not heared,在我添加它之前,我是否需要rake:rollback->rake db:migrate??,我没有异常…@GeorgeKrause不,你不必重做迁移。只需阅读Rails指南中的接受嵌套的属性并应用它。class Customer@customer
上的错误,以查看是否有其他内容阻止保存。检查错误