【问题标题】:Ohm list and unique not working欧姆表和唯一不工作
【发布时间】:2012-04-22 08:53:13
【问题描述】:

文档说欧姆列表被视为 Ruby 数组,但我看到以下问题:

MyModel.new 在 rails 控制台中产生:

ArgumentError: wrong number of arguments (1 for 2)

在我有 list :foo 的那一行,其中 foo 应该是一个整数数组。

然后,为了跟进,我想在 attribute :bar 上创建一个唯一索引,当我注释掉 list 方法并添加唯一时,我得到以下信息:

NoMethodError: undefined method `unique' for MyModel:Class

课程如下:

class MyModel < Ohm::Model
  attribute :email
  list :foo
  unique :email
end

除非我注释掉 list 和 unique 指令,否则整个事情都会崩溃。

【问题讨论】:

标签: ruby-on-rails ruby ohm


【解决方案1】:

你在找assert_unique吗?

class MyModel < Ohm::Model
  attribute :email
  index :email

  def validate
    assert_unique :email
  end
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 2014-10-06
    • 2022-08-24
    • 2012-03-08
    • 2022-08-13
    相关资源
    最近更新 更多