Fanta
2012-Dec-07 15:54 UTC
Save to DB returns false with no error message, how to diagnose it?
Hi. Working along a tutorial, I am trying to create a user for my application, and save it to a User database table. However, when I try to save the user (i.e. add a line to the User table) the Ruby console just returns false, with no explanation. Using *create *instead of *save *does the same. I have tried deleting the database and doing the migration again, but got the same result. How can I obtain more diagnostic on why the save to database is failing? Here a transcript from the console: Loading development environment (Rails 3.2.9) irb(main):001:0> user= User.new screen_name: "ginopino", real_name: "Gino Pilotino", password: "foobar", password_confirmation: "foobar" => #<User id: nil, screen_name: "ginopino", real_name: "Gino Pilotino", created_at: nil, updated_at: nil, password_digest: "$2a$10$T.cnOdhdXPyBt/iQPLGJXuWN62F8FoPgkX9UbXyEWqCh..."> irb(main):002:0> *user.save* ←[1m←[36m (0.0ms)←[0m ←[1mbegin transaction←[0m ←[1m←[35m (0.0ms)←[0m rollback transaction => *false* irb(main):004:0> -- 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@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Wr09mp1vJvAJ. For more options, visit https://groups.google.com/groups/opt_out.
Craig White
2012-Dec-07 16:06 UTC
Re: Save to DB returns false with no error message, how to diagnose it?
On Dec 7, 2012, at 8:54 AM, Fanta wrote:> Hi. Working along a tutorial, I am trying to create a user for my application, and save it to a User database table. However, when I try to save the user (i.e. add a line to the User table) the Ruby console just returns false, with no explanation. Using create instead of save does the same. I have tried deleting the database and doing the migration again, but got the same result. How can I obtain more diagnostic on why the save to database is failing? > > Here a transcript from the console: > > Loading development environment (Rails 3.2.9) > irb(main):001:0> user= User.new screen_name: "ginopino", real_name: "Gino Pilotino", password: "foobar", password_confirmation: "foobar" > => #<User id: nil, screen_name: "ginopino", real_name: "Gino Pilotino", created_at: nil, updated_at: nil, password_digest: "$2a$10$T.cnOdhdXPyBt/iQPLGJXuWN62F8FoPgkX9UbXyEWqCh..."> > irb(main):002:0> user.save > ←[1m←[36m (0.0ms)←[0m ←[1mbegin transaction←[0m > ←[1m←[35m (0.0ms)←[0m rollback transaction > => false > irb(main):004:0>---- these commands might be useful in the console… user.errors user.valid? check log/development.log Craig -- 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@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Fanta
2012-Dec-07 16:16 UTC
Re: Save to DB returns false with no error message, how to diagnose it?
Thank you Craig, that resolved it. user.errors reminded me that I had imposed a constraint on the password length, and my password did not respect it. On Friday, December 7, 2012 5:06:52 PM UTC+1, Craig White wrote:> > > On Dec 7, 2012, at 8:54 AM, Fanta wrote: > > > Hi. Working along a tutorial, I am trying to create a user for my > application, and save it to a User database table. However, when I try to > save the user (i.e. add a line to the User table) the Ruby console just > returns false, with no explanation. Using create instead of save does the > same. I have tried deleting the database and doing the migration again, but > got the same result. How can I obtain more diagnostic on why the save to > database is failing? > > > > Here a transcript from the console: > > > > Loading development environment (Rails 3.2.9) > > irb(main):001:0> user= User.new screen_name: "ginopino", real_name: > "Gino Pilotino", password: "foobar", password_confirmation: "foobar" > > => #<User id: nil, screen_name: "ginopino", real_name: "Gino Pilotino", > created_at: nil, updated_at: nil, password_digest: > "$2a$10$T.cnOdhdXPyBt/iQPLGJXuWN62F8FoPgkX9UbXyEWqCh..."> > > irb(main):002:0> user.save > > ←[1m←[36m (0.0ms)←[0m ←[1mbegin transaction←[0m > > ←[1m←[35m (0.0ms)←[0m rollback transaction > > => false > > irb(main):004:0> > ---- > these commands might be useful in the console… > > user.errors > user.valid? > > check log/development.log > > Craig-- 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@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/DRWNVUjqPJ8J. For more options, visit https://groups.google.com/groups/opt_out.