I am running "rails console" and then the following command:
User.create(name:"John", email:"[email protected]", password:"foo", password_confirmation:"foo")
and i get this:
(0.1ms) begin transaction
User Exists (0.2ms) SELECT 1 FROM "users" WHERE LOWER("users"."email") = LOWER('[email protected]') LIMIT 1
(0.1ms) rollback transaction
=> #<User id: nil, name: "John", email: "[email protected]", created_at: nil, updated_at: nil, password_digest: "$2a$10$mY0/9RgjwOU46ZYcSC0TFOCMxrPiqWTEHWe1K27O/3Ya...">
when i check the file of the sqlite database using SQLite Database browser I see nothing.
here is my user model:
class User < ActiveRecord::Base
#these attributes can be modified by the users
attr_accessible :name, :email, :password, :password_confirmation
#ruby's way of calling a method below...
has_secure_password
#validation testing
validates :name, presence: true, length: { maximum: 50 }
#regular expression (there is an official one)
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
#and add it..
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
#validate password
validates :password, length: {minimum: 6}
validates :password_confirmation, presence: true
end
why is data not entered in my database?
I get this error with whatever I enter!
This for example:
1.9.3p125 :005 > User.create(name:"Smith", email:"[email protected]", password:"foo", password_confirmation:"foo")
(0.1ms) begin transaction
User Exists (0.1ms) SELECT 1 FROM "users" WHERE LOWER("users"."email") = LOWER('[email protected]') LIMIT 1
(0.0ms) rollback transaction
=> #<User id: nil, name: "Smith", email: "[email protected]", created_at: nil, updated_at: nil, password_digest: "$2a$10$6nzyRJ0IplI6B4bSoQEtUOIcrbFVl1ix3EAKPGJZjZQf...">
I never entered a Smith user with that email, and I still get that "User Exists"!
EDIT:
I got the error. The password limit is 5 I was entering a 3-letter password so when I type this:
User.create(name:"Smith", email:"[email protected]", password:"foobar", password_confirmation:"foobar")
(0.1ms) begin transaction
User Exists (0.2ms) SELECT 1 FROM "users" WHERE LOWER("users"."email") = LOWER('[email protected]') LIMIT 1
Binary data inserted for `string` type on column `password_digest`
SQL (1.7ms) INSERT INTO "users" ("created_at", "email", "name", "password_digest", "updated_at") VALUES (?, ?, ?, ?, ?) [["created_at", Mon, 12 Mar 2012 00:16:42 UTC +00:00], ["email", "[email protected]"], ["name", "Smith"], ["password_digest", "$2a$10$v/FqAuUPpbdIJ44jVHxbKOJt/uoBTJVkP4KIhzJHNcF8rWPFfKusi"], ["updated_at", Mon, 12 Mar 2012 00:16:42 UTC +00:00]]
(266.9ms) commit transaction
=> #<User id: 1, name: "Smith", email: "[email protected]", created_at: "2012-03-12 00:16:42", updated_at: "2012-03-12 00:16:42", password_digest: "$2a$10$v/FqAuUPpbdIJ44jVHxbKOJt/uoBTJVkP4KIhzJHNcF8...">
I works, but i still get this weird User Exists error... Any ideas?
[email protected]so the:uniquenessvalidation for the email is failing.user = User.new(name:"Smith", email:"[email protected]", password:"foo", password_confirmation:"foo")and then:puts user.errors?User.create(name:"fwjwof42848yt24", email:"[email protected]", password:"foo", password_confirmation:"foo")and see if you get the same problem.user.errors- it'll tell you what's up.