2011-03-05 113 views
0

我rails3.0.4,并制定有以下用户表设计的登录验证失败

 
create_table "users", :force => true do |t| 
    t.string "login" 
    t.string "email" 
    t.string "crypted_password",   :null => false 
    t.string "password_salt",   :null => false 
    t.string "persistence_token",  :null => false 
    t.string "single_access_token",  :null => false 
    t.string "perishable_token",   :null => false 
    t.datetime "created_at" 
    t.datetime "updated_at" 
    t.string "database_authenticatable", :null => false 
    t.string "recoverable" 
    t.string "rememberable" 
    t.string "trackable" 
    t.string "reset_password_token" 
    end 

用户表不是由色器件创建的,但我添加了必要的 列在迁移安装。 按照在配置/初始化/ devise.rb

config.authentication_keys = [ :email]

但每次我尝试注册时,它抛出一个新的用户时间设置:

 
    2 errors prohibited this user from being saved: 
    Login is too short (minimum is 3 characters) 
    Login should use only letters, numbers, spaces, and [email protected] please. 

任何想法,为什么它会发生?

回答

2

是的,登录太短和/或包含错误的字符:) 您启用了设计内置的验证,这就是他们验证。要使用您自己的验证,请删除:可从您的设计包含在app/models/user.rb中的validatable

如果您有兴趣,devise使用的验证在设计中的lib/devise/models/validatable.rb中定义宝石。

如果验证不是问题,您将不得不显示用户创建请求的日志,以便我们可以看到提交的参数。

编辑:哦,我明白了,我误读 - 这是关于“登录”。好吧,看下面的评论。

+0

这就是日志从log/development.log中发现的日志

 Started POST "/users" for 127.0.0.1 at Sat Mar 05 18:57:34 +0600 2011 Processing by Devise::RegistrationsController#create as HTML Parameters: {"commit"=>"Sign up", "authenticity_token"=>"tA88vTZRWYNPRgbCv2UF65RlUJA8JEjIOaOTGif8jz8=", "utf8"=>"\342\234\223", "user"=>{"password_confirmation"=>"[FILTERED]", "login"=>"administrator", "password"=>"[FILTERED]", "email"=>"[email protected]"}} WARNING: Can't mass-assign protected attributes: login 
Nozim 2011-03-05 13:05:30

+1

“Can not mass-assign protected attributes:login”。在app/models/user.rb中添加:登录到attr_accessible – 2011-03-05 13:11:54