ActiveRecord枚举错误:“不是有效值”

鲍里萨诺

我有一个带有枚举的模型:

  enum pending_users: {
    pending_users_disabled: 0,
    pending_users_enabled: 1
  }

这是schema.rb中描述的字段的方式:

t.integer  "pending_users",             limit: 4,     default: 0, null: false

当我尝试通过带有以下参数的控制器对其进行更新时:

 Parameters: {"utf8"=>"✓", "authenticity_token"=>"...", "group"=>{"pending_users"=>"1"}, "commit"=>"Update Group", "id"=>"33"}

我看到以下错误:

ArgumentError - '1' is not a valid pending_users:
  activerecord (4.2.7.1) lib/active_record/enum.rb:104:in `block (3 levels) in enum'
  activerecord (4.2.7.1) lib/active_record/attribute_assignment.rb:54:in `_assign_attribute'
  activerecord (4.2.7.1) lib/active_record/attribute_assignment.rb:41:in `block in assign_attributes'
  actionpack (4.2.7.1) lib/action_controller/metal/strong_parameters.rb:185:in `each_pair'
  activerecord (4.2.7.1) lib/active_record/attribute_assignment.rb:35:in `assign_attributes'
  activerecord (4.2.7.1) lib/active_record/persistence.rb:251:in `block in update'
  activerecord (4.2.7.1) lib/active_record/transactions.rb:351:in `block in with_transaction_returning_status'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `block in transaction'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/transaction.rb:184:in `within_new_transaction'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/database_statements.rb:213:in `transaction'
  activerecord (4.2.7.1) lib/active_record/transactions.rb:220:in `transaction'
  activerecord (4.2.7.1) lib/active_record/transactions.rb:348:in `with_transaction_returning_status'
  activerecord (4.2.7.1) lib/active_record/persistence.rb:250:in `update'
  app/controllers/groups_controller.rb:53:in `update'

在我看来,1是枚举的有效值。什么会导致这种行为?

奥尔普

您应该为枚举分配一个字符串(键)。所以1应该改为"pending_users_enabled"

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

实例验证错误:*不是*的有效值

来自分类Dev

Python 有效值?

来自分类Dev

如何处理 requestbody 以从枚举设置有效值?

来自分类Dev

枚举错误“成员”不是“枚举”类型

来自分类Dev

Inno Setup-参数“ ValueData”不是有效值

来自分类Dev

CSS 3.0 rotation(90deg)不是'transform'属性的有效值

来自分类Dev

“ defau1t:”(不是“ default:”)是标签的有效值吗?

来自分类Dev

Visual Studio 2012'NaN'不是SharePoint包的'FontSize'的有效值属性

来自分类Dev

Inno Setup-参数“ ValueData”不是有效值

来自分类Dev

CSS 3.0 rotation(90deg)不是'transform'属性的有效值

来自分类Dev

Nuget错误:指定的参数超出有效值范围。参数名称:supportedFrameworks

来自分类Dev

错误:指定的参数超出有效值范围。在RowDataBound Gridview中

来自分类Dev

错误输入后文本框清除有效值 - WPF

来自分类Dev

从存储过程填充下拉列表错误:超出有效值范围

来自分类Dev

Eclipse在pom.xml文件中显示错误:cvc-datatype-valid.1.2.1:'$ {MYVAR}'不是'boolean'的有效值

来自分类Dev

lon&lat的有效值是多少

来自分类Dev

从列表框的ScrollInfo获取有效值

来自分类Dev

用有效值初始化SymmetricAlgorithm

来自分类Dev

Matlab:稀疏矩阵中的有效值分配

来自分类Dev

在Fluent验证中显示有效值

来自分类Dev

lon&lat的有效值是多少

来自分类Dev

什么是抽象xsd元素中的有效值

来自分类Dev

Matlab:稀疏矩阵中的有效值分配

来自分类Dev

LC_CTYPE的有效值?

来自分类Dev

从列表框的ScrollInfo获取有效值

来自分类Dev

hapi joi过滤器有效值

来自分类Dev

仅从JSON检索有效值

来自分类Dev

如何为可视铃设置有效值?

来自分类Dev

url 是查询参数的有效值吗?

Related 相关文章

热门标签

归档