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:in
password=’
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