ActiveResource无法验证属性的确认

时间:2016-05-11 18:53:15

标签: ruby-on-rails validation activeresource

我有这个资源:

require 'active_resource'

class User < ActiveResource::Base
  self.site = 'http://localhost:3000/api/v2'
  self.include_format_in_path = false

  schema do
    attribute :id,                 :integer
    attribute :name,               :string
    attribute :password,           :string
    attribute :email,              :string
  end

  validates :email, confirmation: true
  # alternatively, tried with:
  # validates_confirmation_of :email
end

我打电话的时候:

user = User.new(
  name: 'My name',
  email: 'an@email.com',
  email_confirmation: 'another@email.com',
  password: 'some_password'
)

然后user.errors,我希望它会返回有关email_confirmation不匹配email的错误。但是,它没有。 user.valid?始终返回true

此外,user.email会返回'an@email.com',但user.email_confirmation会返回nil

我也测试了验证密码,看起来任何user.xxx_confirmation都会返回nil

我们如何验证ActiveResource上的确认?

0 个答案:

没有答案