Hello, I am adding a basic authentication scheme to my application. When I go to the console and try to add a new User I''m getting an error which I don''t know what to do with. Any help would be wonderful. Here''s my console session:>> u = User.new=> #<User:0x32f8aac @attributes={"username"=>nil, "password"=>nil}, @new_record=true>>> u.password = ''test''NameError: uninitialized constant User::MD5 from /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing'' from ./script/../config/../config/../app/models/user.rb:16:in `password='' from (irb):2>>Here''s my User model: class User < ActiveRecord::Base require ''digest/md5'' def self.authenticate(name, password) user = User.find(:first, :conditions => ["name = ? AND password = ?", name, MD5.md5(password).hexdigest]) if user.blank? raise "Name or password is invalid" end user end def password=(pswd) self.password = MD5.md5(pswd).hexdigest end end I think it''s not finding the digest/md5 file. If that''s the case I''m not really sure how to remedy that. Thanks, William -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
replace MD5.md5(''password'').hexdigest with Digest::MD5.hexdigest(''password'') On 7/17/07, William Lefevre <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hello, > I am adding a basic authentication scheme to my application. When I > go to the console and try to add a new User I''m getting an error which I > don''t know what to do with. Any help would be wonderful. > > Here''s my console session: > > >> u = User.new > => #<User:0x32f8aac @attributes={"username"=>nil, "password"=>nil}, > @new_record=true> > >> u.password = ''test'' > NameError: uninitialized constant User::MD5 > from > /usr/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in > `const_missing'' > from ./script/../config/../config/../app/models/user.rb:16:in > `password='' > from (irb):2 > >> > > > Here''s my User model: > > class User < ActiveRecord::Base > > require ''digest/md5'' > > def self.authenticate(name, password) > user = User.find(:first, > :conditions => ["name = ? AND password = ?", > name, MD5.md5(password).hexdigest]) > if user.blank? > raise "Name or password is invalid" > end > user > end > > def password=(pswd) > self.password = MD5.md5(pswd).hexdigest > end > > end > > I think it''s not finding the digest/md5 file. If that''s the case I''m not > really sure how to remedy that. > > Thanks, > William > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Chris Hall wrote:> replace > > MD5.md5(''password'').hexdigest > > with > > Digest::MD5.hexdigest(''password'')Thank you. That did the trick. I''m not sure why the syntax changed. I copied ''MD5.md5(''password'').hexdigest, from a test site I did over a year ago which worked just fine. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---