嵌套表单中的批量分配失败

时间:2012-05-18 15:03:40

标签: ruby-on-rails-3

我遇到了新手面对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

我尝试将accepts_nested_attributes_for:user_impl,:util_location添加到代码中,但这也无法正常工作并产生完全不同的错误。

1 个答案:

答案 0 :(得分:1)

基本结构应如下:

class User < ActiveRecord::Base
    attr_accessible :user_impl_attributes

    has_one :user_impl, :dependent => :destroy
    accepts_nested_attributes_for :user_impl