Possible Duplicate:
Can't convert String into integer in ruby/ruby-on-rails
I’m running through a tutorial on Lynda for learning rails and I’m running into a problem. I’ve built an AccessController to work with an AdminUser model I have. I’m using a string/time salt combo and saving that to the Db, then trying to authenticate using a login form. Here is some code from AccessController
def attempt_login
authorized_user = AdminUser.authenticate(params[:username], params[:password])
#authorized_user = nil
if authorized_user
flash[:notice] = "You are logged in now"
redirect_to(:action => 'menu')
else
flash[:notice] = "invalid username/password combo"
redirect_to(:action => 'login')
end
end
And then some from my model where I define the authenticate method:
def self.authenticate(username="", password="")
user = AdminUser.find_by_username(username)
if user && user.password_match?(password)
return user
else
return false
end
end
def password_match?(password="")
hashed_password == AdminUser.hash_with_salt(password, salt)
end
All the hash_with_salt method does is take salt from the DB for that user and makes sure the password entered is salted/encryped with the same salt. Here’s the error I’m continuously getting:
TypeError in AccessController#attempt_login
can't convert String into Integer
Rails.root: /Users/UNAME/Sites/simple_cms
Application Trace | Framework Trace | Full Trace
activesupport (3.1.3) lib/active_support/descendants_tracker.rb:22:in `delete'
activesupport (3.1.3) lib/active_support/descendants_tracker.rb:22:in `block in clear'
activesupport (3.1.3) lib/active_support/descendants_tracker.rb:20:in `each'
activesupport (3.1.3) lib/active_support/descendants_tracker.rb:20:in `clear'
railties (3.1.3) lib/rails/application/bootstrap.rb:56:in `block (2 levels) in <module:Bootstrap>'
activesupport (3.1.3) lib/active_support/callbacks.rb:395:in `_run_cleanup_callbacks'
activesupport (3.1.3) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.1.3) lib/action_dispatch/middleware/reloader.rb:72:in `rescue in call'
actionpack (3.1.3) lib/action_dispatch/middleware/reloader.rb:67:in `call'
rack (1.3.6) lib/rack/sendfile.rb:101:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
railties (3.1.3) lib/rails/rack/logger.rb:13:in `call'
rack (1.3.6) lib/rack/methodoverride.rb:24:in `call'
rack (1.3.6) lib/rack/runtime.rb:17:in `call'
activesupport (3.1.3) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.3.6) lib/rack/lock.rb:15:in `call'
actionpack (3.1.3) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.1.3) lib/rails/engine.rb:456:in `call'
rack (1.3.6) lib/rack/content_length.rb:14:in `call'
railties (3.1.3) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.3.6) lib/rack/handler/webrick.rb:59:in `service'
/Users/UNAME/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/Users/UNAME/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/Users/UNAME/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
Any help would be greatly appreciated. I’m certain I’m doing the exact same thing as the tutorial, but maybe there’s an error because of differing Ruby/Rails versions? Searched for hours on this with most of the results discussing the inject() method and that is not helpful. Thanks again!
I had this same problem and spent hours trying to fix it. It turned out that I had left in a method that the tutorial had told me to delete a few videos beforehand:
In the tutorial, this had been replaced by the methods
Once I commented this method out, the error went away. I still don’t understand why that error showed up in the first place. I added a question and more detail here.