当前位置 : 主页 > 编程语言 > ruby >

ruby-on-rails – 使用Authlogic保存用户时,Crypted_pa​​ssword为null

来源:互联网 收集:自由互联 发布时间:2021-06-23
我尝试时,我的生产安装上出现了一个奇怪的错误 使用AL创建一个新用户: ActiveRecord :: StatementInvalid:Mysql :: Error:Column ‘crypted_pa​​ssword’不能为null:INSERT INTO用户 特别奇怪的b / c它
我尝试时,我的生产安装上出现了一个奇怪的错误
使用AL创建一个新用户:

ActiveRecord :: StatementInvalid:Mysql :: Error:Column
‘crypted_pa​​ssword’不能为null:INSERT INTO用户

特别奇怪的b / c它在我当地的盒子上按预期工作.

两个盒子上的RUNning Rails 2.3.2和ruby 1.8.7.

user.rb:
class User < ActiveRecord::Base
 before_create :set_username
  acts_as_authentic do |c|
    c.require_password_confirmation = false
    c.login_field = "email"
    c.validates_length_of_password_field_options = {:minimum => 4}  
    c.validate_login_field = false  #don't validate email field with additional validations 
  end
end

这是我的生产控制台的输出:

>> u = User.new
=> #<User id: nil, username: nil, email: nil, crypted_password: nil,
    password_salt: nil, persistence_token: nil, single_access_token: nil,
    perishable_token: nil, login_count: 0, failed_login_count: 0,
    last_request_at: nil, current_login_at: nil, last_login_at: nil,
    current_login_ip: nil, last_login_ip: nil, created_at: nil,
    updated_at: nil, is_admin: 0, first_name: nil, last_name: nil>

>> u.full_name = 'john smith'
=> "john smith"
>> u.password = 'test'
=> "test"
>> u.email = 't...@example.com'

=> "t...@example.com"
>> u.valid?
=> true
>> u.save

ActiveRecord::StatementInvalid: Mysql::Error: Column
'crypted_password' cannot be null: INSERT INTO `users`
(`single_access_token`, `last_request_at`, `created_at`,
`crypted_password`, `perishable_token`, `updated_at`, `username`,
`failed_login_count`, `current_login_ip`, `password_salt`,
`current_login_at`, `is_admin`, `persistence_token`, `login_count`,
`last_name`, `last_login_ip`, `last_login_at`, `email`, `first_name`)
VALUES('B-XSXwhO7hkbtISIOyEq', NULL, '2009-07-31 01:10:44', NULL,
'FK3mYS2Tp5Tzeq5IXE1z', '2009-07-31 01:10:44', 'john', 0, NULL, NULL,
NULL, 0,
'2c76b645f761eb3509353290e93874cecdb68a63caa165812ab1b126d63660757090ecf69995caef9e78f93d070b524e2542b3fec4ee050726088c2a9fdb0c9f',
0, 'smith', NULL, NULL, 't...@example.com', 'john')
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/abstract_adapter.rb:212:in `log'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/mysql_adapter.rb:320:in `execute'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
259:in `insert_sql'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/mysql_adapter.rb:330:in `insert_sql'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
44:in `insert_without_query_dirty'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/abstract/query_cache.rb:18:in
`insert'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2902:in `create_without_timestamps'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/timestamp.rb:29:in `create_without_callbacks'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/callbacks.rb:266:in `create'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2868:in `create_or_update_without_callbacks'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/callbacks.rb:250:in `create_or_update'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/base.rb:2539:in `save_without_validation'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/validations.rb:1009:in `save_without_dirty'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/dirty.rb:79:in `save_without_transactions'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:229:in `send'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:229:in
`with_transaction_returning_status'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/connection_adapters/abstract/database_statements.rb:
136:in `transaction'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:182:in `transaction'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:228:in
`with_transaction_returning_status'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:196:in `save'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:208:in `rollback_active_record_state!'
        from /usr/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/
active_record/transactions.rb:196:in `save'

不知道为什么会发生这种情况,特别是为什么这会在dev上保存新用户但不在生产中.非常感谢任何帮助,谢谢!

编辑:使用Apache&乘客2.2.4

acts_as_authentic混合密码和密码=方法. password =方法接受您的纯文本密码,将其加密并加密.

也许您已经在用户模型中重新定义了password =方法,就像使用attr_accessor:password一样?

网友评论