Forum: Ruby on Rails Problem with the Authorization recipe

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ana B. (Guest)
on 2006-04-21 08:57
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 ./script/../config/../config/../app/models/user.rb:5:in `password='
from (irb):4

and here are my model:

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

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 :)
Steve R. (Guest)
on 2006-04-21 09:28
(Received via mailing list)
You required digest/sha2 right?
View this message in context:
Sent from the RubyOnRails Users forum at
Ana B. (Guest)
on 2006-04-21 09:46
Steve R. wrote:
> You required digest/sha2 right?
> --
> View this message in context:
> Sent from the RubyOnRails Users forum at

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
 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. (Guest)
on 2006-04-21 09:52
(Received via mailing list)
Typo - it should be 'hexdigest', not 'hexidigest'
Ana B. (Guest)
on 2006-04-21 10:00
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 ;)
This topic is locked and can not be replied to.