Problem with the Authorization recipe

I just got the rails recipes book and i couldnt be more happy, but
inside the book there are some details, mostly typos but this one its
one i cant fix, im following the Authorization recipe on page 128 i
create the table and the model, the problem comes when i try to assign a
password to a user in the console, here is the output:

justin = User.create(:username => “justin”)
=> #<User:0x3c9cd38 @errors=#<ActiveRecord::Errors:0x3c9b730 @errors={},
@base=#<User:0x3c9cd38 …>>, @attributes={“password_salt”=>nil,
“username”=>“justin”, “id”=>4, “password_hash”=>nil}, @new_record=false>

justin.password = “secret”
NameError: uninitialized constant Digest::SHA2
from
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:89:in
const_missing' from ./script/../config/../config/../app/models/user.rb:5:inpassword=’
from (irb):4

and here are my model:

class User < ActiveRecord::Base
validates_uniqueness_of :username
def password=(pass)
salt = [Array.new(6){rand(256).chr}.join].pack(“m”).chomp
self.password_salt, self.password_hash = salt,
Digest::SHA256.hexidigest(pass + salt)
end
end

Its clearly seems to be a problem of the SHA2 library but searching
around i cant find any reasonable info that helps to fix this problem,
hope someone can give me a hand with this :slight_smile:

You required digest/sha2 right?

View this message in context:
http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608
Sent from the RubyOnRails Users forum at Nabble.com.

Typo - it should be ‘hexdigest’, not ‘hexidigest’

Steve R. wrote:

You required digest/sha2 right?

View this message in context:
http://www.nabble.com/Problem-with-the-Authorization-recipe-t1484569.html#a4020608
Sent from the RubyOnRails Users forum at Nabble.com.

ok, dumb mistakenow i required sha2: require ‘digest/sha2’ but the
problems keep coming, now i get this when trying to assign a password:

negro3.password = “secret”
NoMethodError: undefined method hexidigest' for Digest::SHA256:Class from ./script/../config/../config/../app/models/user.rb:6:in password=’
from (irb):3

Im using windows/rails1.1/ruby1.8.4 even in the forums of the recipes
book i cant find a good answer to fix this.

David M. wrote:

Typo - it should be ‘hexdigest’, not ‘hexidigest’

oh no¡ no no no, i have 3 hours working in how to fix this problem, all
was a simple thing, that typo.

Thanks so much for your help guys, really :wink: