我正在尝试通过我的 Rails 控制台将新记录插入 SQLiteDB。只需使用User.create()
.
该行未出现在我的数据库中。该消息暗示用户存在,但调用User.first
返回null
并检查数据库显示一个空表。我错过了什么?
输入:
console > User.create(name: 'don', email: 'don@gmaill.com', password: 'test', password_confirmation: 'test')
输出:
(0.1ms) begin transaction
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = 'don@gmaill.com' LIMIT 1
(0.0ms) rollback transaction
=> #<User id: nil, name: "don", email: "don@gmaill.com", created_at: nil, updated_at: nil, password_digest: "$2a$10$3EK3L932ryjrJPFIc4E0/uzavrpkWylDRzx4Wkdwzx8d...">
用户等级:
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sen,sitive: false }
has_secure_password
validates :password, length: { minimum: 6 }
end