跳至内容 跳至搜索

Active Model UnknownAttributeError

当通过批量赋值提供未知属性时引发异常。

class Person
  include ActiveModel::AttributeAssignment
  include ActiveModel::Validations
end

person = Person.new
person.assign_attributes(name: 'Gorby')
# => ActiveModel::UnknownAttributeError: unknown attribute 'name' for Person.
方法
N

属性

[R] attribute
[R] record

类公共方法

new(record, attribute)

# File activemodel/lib/active_model/errors.rb, line 541
def initialize(record, attribute)
  @record = record
  @attribute = attribute
  super("unknown attribute '#{attribute}' for #{@record.class}.")
end