I am new to rails and I have problems with the console. I would like to add entries to my users table and check out some features. However, every time I execute the User.create function or a similar function, it succeeds and then returns immediately. How to prevent an immediate rollback?
I'm not in sandbox mode.
Below is the output that I get in the console when I try to create a user. He says the user exists, and then immediately rolls back the transaction. Then I run User.all to show that the transaction is really a rollback.
>>> User.create(first_name: "derek", last_name: "harrington", email: " derek@gmail.com ") (0.1ms) begin transaction User Exists (0.2ms) SELECT 1 FROM "users" WHERE "users"."email" = ' derek@gmail.com ' LIMIT 1 (0.1ms) rollback transaction => #<User id: nil, first_name: "derek", last_name: "harrington", email: " derek@gmail.com ", password_digest: nil, credit_card_id: nil, address_id: nil, created_at: nil, updated_at: nil> >>> User.all User Load (0.3ms) SELECT "users".* FROM "users" => []
How to make these changes permanent and prevent rollback?
Edit:
Here are the contents of my User model
class User < ActiveRecord::Base attr_accessible :first_name, :last_name, :email, :password, :password_confirmation has_secure_password validates :first_name, presence: true, length: { maximum: 50 } validates :last_name, presence: true, length: { maximum: 50 } VALID_EMAIL_REGEX = /\A[\w+\-.] +@ [az\d\-.]+\.[az]+\z/i validates :email, presence: true, format: { with: VALID_EMAIL_REGEX }, uniqueness: true validates :password, confirmation: true, length: { minimum: 6, maximum: 50 } validates :password_confirmation, presence: true end