John Merlino
2010-Dec-13 23:46 UTC
NoMethodError undefined method `password'' for #<User:0x102295b28>
Hey all, I''m following the Authenticating Your Users Recipe in Rails recipes, which is a bit outdated I know. It says run a migration: def self.up create_table :users do |t| t.column "username", :string t.column "password_salt", :string t.column "password_hash", :string end end And then create a form: <% form_for @user, :url => { :action => "signup" } do |f| %> <%= f.label(:username, "username")%> <%= f.text_field(:username) %><br/> <%= f.label(:password, "password")%> <%= f.password_field(:password) %><br/> <%= f.submit("Sign Up")%> <% end %> #Note that he''s using the now defunct start_from_tag Problem is because I don''t have a password field in users table in database, I think it gives undefined method error for password when I pass as argument in the password_field() method. However, in the book, he does exactly that and it works for him. Is there anything I''m doing wrong? Thanks for response. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2010-Dec-14 00:07 UTC
Re: NoMethodError undefined method `password'' for #<User:0x102295b28>
On Dec 13, 2010, at 3:46 PM, John Merlino wrote:> Hey all, > > I''m following the Authenticating Your Users Recipe in Rails recipes, > which is a bit outdated I know. > > It says run a migration: > > def self.up > create_table :users do |t| > t.column "username", :string > t.column "password_salt", :string > t.column "password_hash", :string > end > end > > And then create a form: > > <% form_for @user, :url => { :action => "signup" } do |f| %> > > <%= f.label(:username, "username")%> > <%= f.text_field(:username) %><br/> > <%= f.label(:password, "password")%> > <%= f.password_field(:password) %><br/> > <%= f.submit("Sign Up")%> > > <% end %> > #Note that he''s using the now defunct start_from_tag > > Problem is because I don''t have a password field in users table in > database, I think it gives undefined method error for password when I > pass as argument in the password_field() method. However, in the book, > he does exactly that and it works for him. > > Is there anything I''m doing wrong?What''s your model look like? You''ll want the following in your User model... attr :password And some hooks to convert that into password_hash I suppose as well... -philip -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Marnen Laibow-Koser
2010-Dec-14 00:08 UTC
Re: NoMethodError undefined method `password'' for #<User:0x102295b28>
John Merlino wrote in post #968183:> Hey all, > > I''m following the Authenticating Your Users Recipe in Rails recipes, > which is a bit outdated I know. > > It says run a migration: > > def self.up > create_table :users do |t| > t.column "username", :string > t.column "password_salt", :string > t.column "password_hash", :string > end > end > > And then create a form: > > <% form_for @user, :url => { :action => "signup" } do |f| %> > > <%= f.label(:username, "username")%> > <%= f.text_field(:username) %><br/> > <%= f.label(:password, "password")%> > <%= f.password_field(:password) %><br/> > <%= f.submit("Sign Up")%> > > <% end %> > #Note that he''s using the now defunct start_from_tag > > Problem is because I don''t have a password field in users table in > database, I think it gives undefined method error for password when I > pass as argument in the password_field() method. However, in the book, > he does exactly that and it works for him. > > Is there anything I''m doing wrong?The example should never have worked, unless he''s relying on some particular authentication library (or an attr_accessor call) to create the password method. However, you''re doing two things wrong here: * Following an outdated book * Trying to roll your own authentication library -- just go with Authlogic or Devise.> > Thanks for response.Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
John Merlino
2010-Dec-14 02:25 UTC
Re: NoMethodError undefined method `password'' for #<User:0x102295b28>
> However, you''re doing two things wrong here: > * Following an outdated book > * Trying to roll your own authentication library -- just go with > Authlogic or Devise.This is for a personal project that doesn''t require rapid development. I''m just trying to build my own authentication system so I can better understand the Rails environment. Like you said, perhaps he''s declaring a setter and getter method of the User class with the identifier of "password". Nevertheless nowhere is it explained how to translate this to a password hash in this book. I looked at the Advanced Recipes book and it doesn''t cover authentication at all. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.