0

这是我的用户模型:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable, :token_authenticatable, :confirmable, :timeoutable, 
         :recoverable, :rememberable, :trackable, :validatable,
                 :email_regexp =>  /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i

  attr_accessible :email, :password, :password_confirmation, :remember_me, :name, :confirmed_at, :confirmation_token, :category_ids
    validates_uniqueness_of :email, :case_sensitive => false
    validates_confirmation_of   :password

end

当我输入数据库中存在的电子邮件地址时,我的页面不会重新加载,也看不到任何错误消息或任何内容。

这是我在日志中看到的:

Started GET "/validators/uniqueness?case_sensitive=false&user%5Bemail%5D=abc%40email.com" for 127.0.0.1 at 2012-06-21 03:59:57 -0500
  User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE ("users"."email" LIKE 'abc@email.com') LIMIT 1


Started GET "/validators/uniqueness?case_sensitive=false&user%5Bemail%5D=abc%40email.com" for 127.0.0.1 at 2012-06-21 03:59:57 -0500
  User Exists (0.2ms)  SELECT 1 AS one FROM "users" WHERE ("users"."email" LIKE 'abc@email.com') LIMIT 1
4

2 回答 2

0

“解决方案是改为执行完全自定义的验证,或者像您在示例中所做的那样覆盖电子邮件验证

https://github.com/bcardarella/client_side_validations/issues/455#issuecomment-12170527

于 2013-04-18T18:25:58.457 回答
0

你为什么要覆盖设计验证?设计将处理一切。日志表明您正在尝试进行某种 JS 表单验证,对吗?如果是这样,请尝试以不同方式检查现有用户:

email = params[:email] || ""
@exists = User.where(:email=>email.downcase).count
于 2012-06-21T11:27:12.437 回答