I''m using Restful Authentication, and the code to create a user is pretty straight forward - there is a before_save action and a before_create action: before_save :encrypt_password before_create :make_activation_code But for some reason when I try to create a user programmatically in the controller like this: User.new(:email => ''user-n8tE+Mx9DRM@public.gmane.org'', :password => ''123456'', :password_confirmation => ''123456'') Nothing happens. I get a user that I can''t save:> u = User.new(:email => ''user-n8tE+Mx9DRM@public.gmane.org'', :password => ''123456'', :password_confirmation => ''123456'')=> #<User id: nil, login: nil, email: "user-n8tE+Mx9DRM@public.gmane.org", crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, remember_token: nil, remember_token_expires_at: nil, activation_code: nil, activated_at: nil, is_seller: false>>> u.save=> false Any clues as to how I could create a user without actually being sent to the user controller''s create action? The before_save and before_create actions are private. Thanks, Nik --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nik, The default generator for restful_authentication creates a user model with the constraint "validates_presence_of :login". Unless you removed this from the user model you''ll need to supply a login. Also, did you check the errors on the user model after the failed save to see why it''s not saving? u.errors (using your example) will give you the list of errors. Best. Mike On Jun 29, 2008, at 9:56 AM, Nik B wrote:> > I''m using Restful Authentication, and the code to create a user is > pretty straight forward - there is a before_save action and a > before_create action: > > before_save :encrypt_password > before_create :make_activation_code > > But for some reason when I try to create a user programmatically in > the controller like this: > > User.new(:email => ''user-n8tE+Mx9DRM@public.gmane.org'', :password => > ''123456'', :password_confirmation => ''123456'') > > Nothing happens. I get a user that I can''t save: > >> u = User.new(:email => ''user-n8tE+Mx9DRM@public.gmane.org'', :password => >> ''123456'', :password_confirmation => ''123456'') > => #<User id: nil, login: nil, email: "user-n8tE+Mx9DRM@public.gmane.org", > crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, > remember_token: nil, remember_token_expires_at: nil, activation_code: > nil, activated_at: nil, is_seller: false> >>> u.save > => false > > Any clues as to how I could create a user without actually being sent > to the user controller''s create action? The before_save and > before_create actions are private. > > Thanks, > Nik > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks mike - I did remove this constraint... but I did not remove the constraint that login must be unique... so it was conflicting with a previous user that has a login of '' '' On Jun 29, 10:12 am, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Nik, > > The default generator for restful_authentication creates a user model > with the constraint "validates_presence_of :login". Unless you > removed this from the user model you''ll need to supply a login. > > Also, did you check the errors on the user model after the failed save > to see why it''s not saving? u.errors (using your example) will give > you the list of errors. > > Best. > Mike > > On Jun 29, 2008, at 9:56 AM, Nik B wrote: > > > > > I''m using Restful Authentication, and the code to create a user is > > pretty straight forward - there is a before_save action and a > > before_create action: > > > before_save :encrypt_password > > before_create :make_activation_code > > > But for some reason when I try to create a user programmatically in > > the controller like this: > > > User.new(:email => ''u...-n8tE+Mx9DRM@public.gmane.org'', :password => > > ''123456'', :password_confirmation => ''123456'') > > > Nothing happens. I get a user that I can''t save: > > >> u = User.new(:email => ''u...-n8tE+Mx9DRM@public.gmane.org'', :password => > >> ''123456'', :password_confirmation => ''123456'') > > => #<User id: nil, login: nil, email: "u...-n8tE+Mx9DRM@public.gmane.org", > > crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, > > remember_token: nil, remember_token_expires_at: nil, activation_code: > > nil, activated_at: nil, is_seller: false> > >>> u.save > > => false > > > Any clues as to how I could create a user without actually being sent > > to the user controller''s create action? The before_save and > > before_create actions are private. > > > Thanks, > > Nik--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Next time use #save! rather than #save to get validation errors. Alternatively you can also view the errors on the object by calling #errors and looking at what''s in there (e.g., puts user.errors). --Jeremy On Sun, Jun 29, 2008 at 9:18 AM, Nik B <nikbauman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Thanks mike - I did remove this constraint... but I did not remove the > constraint that login must be unique... so it was conflicting with a > previous user that has a login of '' '' > > On Jun 29, 10:12 am, Michael Breen <hard...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Nik, >> >> The default generator for restful_authentication creates a user model >> with the constraint "validates_presence_of :login". Unless you >> removed this from the user model you''ll need to supply a login. >> >> Also, did you check the errors on the user model after the failed save >> to see why it''s not saving? u.errors (using your example) will give >> you the list of errors. >> >> Best. >> Mike >> >> On Jun 29, 2008, at 9:56 AM, Nik B wrote: >> >> >> >> > I''m using Restful Authentication, and the code to create a user is >> > pretty straight forward - there is a before_save action and a >> > before_create action: >> >> > before_save :encrypt_password >> > before_create :make_activation_code >> >> > But for some reason when I try to create a user programmatically in >> > the controller like this: >> >> > User.new(:email => ''u...-n8tE+Mx9DRM@public.gmane.org'', :password => >> > ''123456'', :password_confirmation => ''123456'') >> >> > Nothing happens. I get a user that I can''t save: >> >> >> u = User.new(:email => ''u...-n8tE+Mx9DRM@public.gmane.org'', :password => >> >> ''123456'', :password_confirmation => ''123456'') >> > => #<User id: nil, login: nil, email: "u...-n8tE+Mx9DRM@public.gmane.org", >> > crypted_password: nil, salt: nil, created_at: nil, updated_at: nil, >> > remember_token: nil, remember_token_expires_at: nil, activation_code: >> > nil, activated_at: nil, is_seller: false> >> >>> u.save >> > => false >> >> > Any clues as to how I could create a user without actually being sent >> > to the user controller''s create action? The before_save and >> > before_create actions are private. >> >> > Thanks, >> > Nik > > >-- http://jeremymcanally.com/ http://entp.com Read my books: Ruby in Practice (http://manning.com/mcanally/) My free Ruby e-book (http://humblelittlerubybook.com/) Or, my blogs: http://mrneighborly.com http://rubyinpractice.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 -~----------~----~----~----~------~----~------~--~---