【发布时间】:2014-02-19 01:16:03
【问题描述】:
我正在使用 Rails 3.2。我正在尝试为 has_one 关系构建一个对象(每个驱动程序都有一个 cdl_driving_license)。我以前做过很多次类似的任务,而且效果很好。这种特殊情况我不断收到此错误:
undefined method `serialized_attributes' for nil:NilClass
这是我的相关代码:
驱动程序.rb
has_one :cdl_driving_license, dependent: :destroy
accepts_nested_attributes_for :cdl_driving_license, :allow_destroy => true
cdl_driving_license.rb
belongs_to :driver
drivers_controller.rb
def new
@driver = Driver.new
@driver.build_cdl_driving_license
#more code...
end
知道是什么导致了这个错误吗?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3.2 associations