Search code examples
ruby-on-railsdatabasedevisedatabase-migrationbcrypt

self.save! produces an argument error #<ArgumentError: wrong number of arguments (0 for 2)>


I'm overwritting Devise's valid_password function with the follwing:

  def valid_password?(password)
   if legacy_password?
     return false unless Devise.secure_compare(self.encrypted_password,
                                               legacy_password(password, self.encrypted_password))

    attributes = { password:               password,
                   password_confirmation:  password,
                   legacy_password:        false }

    save!
   end
   super password
  end

My trace shows that everything is being set properly (the new encrypted_password) but when the process reaches save! it returns #<ArgumentError: wrong number of arguments (0 for 2)>

Help appreciated!

Update:

When I go through the fields it looks like password and password_confirmation are being set properly but legacy_password is what is returning the error. Additionally, in the console when I enter User.legacy_password I get the same error. Is this an issue with the database?

I recently added legacy_password as a migration.

class AddLegacyPasswordToSpreeUsers < ActiveRecord::Migration
 def up
  add_column :spree_users, :legacy_password, :boolean
 end

 def down
  remove_column :spree_users, :legacy_password
 end

end


Solution

  • Turns out I had a method by the same name (legacy_password). When I was trying to update the attribute it was calling the method (which required 2 parameters) and returning the aforementioned error.