1

我面临一个新手在使用 Rails 3.2.3 时遇到的常见问题。我收到错误

无法批量分配受保护的属性:user_impl、util_location

class User < ActiveRecord::Base

  has_one :user_impl, :dependent => :destroy
  has_one :util_location, :as => :locatable, :dependent => :destroy

  attr_accessible ..., :user_impl_attributes, :util_location_attributes

我尝试将 Accept_nested_attributes_for :user_impl, :util_location 添加到代码中,但这也不起作用并给出了完全不同的错误。

4

1 回答 1

1

基本结构应如下所示:

class User < ActiveRecord::Base
    attr_accessible :user_impl_attributes

    has_one :user_impl, :dependent => :destroy
    accepts_nested_attributes_for :user_impl
于 2012-05-18T15:22:40.670 回答