ruby - Undefined authenticated? method in Rails 4 -


i'm reading book (beginning rails 3), trying on rails 4.

so, have 1 problem:

  def self.authenticate(email, password)     user = where('email = ?', email)     return user if user && user.authenticated?(password)   end    def authenticated?(password)     self.hashed_password == encrypt(password)   end 

when in rails console:

user.authenticate('test@test.com', 123) 

rails returns me error, undefined method authenticated?.

  irb(main):034:0> user.authenticate('test@test.com', 123)   nomethoderror:   ←[1m←[35muser load (1.0ms)←[0m  select "users".* "users" (email = 'test@test.com')   undefined method `authenticated?' #<activerecord::relation []>           c:/railsinstaller/ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/relation/delegati   on.rb:121:in `method_missing'           c:/railsinstaller/ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerecord-4.0.0/lib/active_record/relation/delegati   on.rb:68:in `method_missing'           c:/sites/rails-estudo-blog/app/models/user.rb:23:in `authenticate'           (irb):34           c:/railsinstaller/ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:90:in `st   art'           c:/railsinstaller/ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands/console.rb:9:in `sta   rt'           c:/railsinstaller/ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-4.0.0/lib/rails/commands.rb:64:in `<top (requ   ired)>'           bin/rails:4:in `require'           bin/rails:4:in `<main>'   irb(main):035:0> 

what's wrong?


  • rails 4.0
  • ruby 2.0
  • windows 7 x64

instead of user = where('email = ?', email) should have user = where('email = ?', email).first


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -