views:

1172

answers:

5

i'm getting a strange error on my production install when i try and create a new user using AL:

ActiveRecord::StatementInvalid: Mysql::Error: Column 'crypted_password' cannot be null: INSERT INTO users

especially strange b/c it works as expected on my local box.

RUnning Rails 2.3.2 and ruby 1.8.7 on both boxes.

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

Here's output from my production console:

>> 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 = '[email protected]'

=> "[email protected]"
>> 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, '[email protected]', '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'

No idea why this is happening, and especially why this saves a new user on dev but not on production. Any help is much appreciated, thanks!

edit: using Apache & Passenger 2.2.4

A: 

Do you have installed the same gem versions of authlogic installed in your production/development system?

Lichtamberg
yes, authlogic (2.1.1) in both.
kareem
A: 

Getting the same error on my copy of a project however another developer has no problems.

Trying this:

http://railsforum.com/viewtopic.php?id=7414

+2  A: 

acts_as_authentic mixes in password and password= methods. The password= method takes your plain text password, salts it and encrypts it.

Maybe you have redefined the password= method in your user model, like with attr_accessor :password?

Excellent. I ran into exactly this problem when switching from an older authentication system to authlogic. There was an attr_accessor :password hiding in my user model.
jdl
+1  A: 

Authlogic fills crypted_password and password_salt with null when you'll overwrite accessors like this

attr_accessor :password, :password_confirmation

Those params should be in attr_accessible only

Artur79
A: 

hi i am also having the same problem. i have authlogic (2.1.3) installed as gem in script/console when i tried to create new user i dosent allow me to save it i did the following Admin is single table inheritance of User model u=Admin.new

a.username="blah" a.password="pass" a.password_confirmation ="pass" a.email="[email protected]" a.account_id=1 a.save

i got the following errors a.errors produces

, @base=#>

and a.save produces NoMethodError: undefined method params' for #<Object:0x3794c> from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/controller_adapters/abstract_adapter.rb:30:inparams' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/params.rb:96:in params_credentials' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/params.rb:72:inparams_enabled?' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/params.rb:66:in persist_by_params' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:insend' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:178:in evaluate_method' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:166:incall' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:93:in run' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:ineach' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:in send' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:inrun' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:276:in run_callbacks' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/callbacks.rb:79:inpersist' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/persistence.rb:55:in persisting?' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/session/persistence.rb:39:infind' from /Users/me/.gem/ruby/1.8/gems/authlogic-2.1.3/lib/authlogic/acts_as_authentic/session_maintenance.rb:96:in get_session_information' ... 8 levels... from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:92:inrun' from /Users/me/.gem/ruby/1.8/gems/activesupport-2.3.5/lib/active_support/callbacks.rb:276:in run_callbacks' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:344:incallback' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/callbacks.rb:249:in create_or_update' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/base.rb:2538:insave_without_validation' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/validations.rb:1078:in save_without_dirty' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/dirty.rb:79:insave_without_transactions' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:in send' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:229:inwith_transaction_returning_status' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in transaction' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:182:intransaction' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:228:in with_transaction_returning_status' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:insave' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:208:in rollback_active_record_state!' from /Users/me/.gem/ruby/1.8/gems/activerecord-2.3.5/lib/active_record/transactions.rb:196:insave' from (irb):24 please some one help me out from this problem... thanks

gagan