Wrong argument error when running Rails 1.1.6 with Ruby 1.8.6

Posted by tohchye

If you encounter the following error when you start your rails version 1.1.6 application and you are using ruby 1.8.6.

ArgumentError (wrong number of arguments (1 for 0)):
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `initialize'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `new'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:551:in `scramble41'
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb:141:in `real_connect'    /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:330:in `connect'  /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:87:in `initialize'

it’s actually due to changes in Digest initialization method. The new method no longer supports instantiation with parameters. The offending code is in

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/vendor/mysql.rb

at line 551 within method 'scramble41(password, message)'

    s1 = Digest::SHA1.new(password).digest
    s2 = Digest::SHA1.new(s1).digest
    x = Digest::SHA1.(message + s2).digest

To resolve, just change the code to the following


    s1 = Digest::SHA1.digest(password)
    s2 = Digest::SHA1.digest(s1)
    x = Digest::SHA1.digest(message + s2)

Alternatively you can upgrade your rails version to 1.2.x.

Comments

Leave a response