@accountTemp = Hash.new
@accountTemp['name'] = 'aijinsong'
@accountTemp['email'] = '[email protected]'
@accountTemp['password'] = 'aiajsajs'
@accountTemp['password_confirmation'] = 'aiajsajs'
Account.create(@accountTemp)
上面这段代码执行后会有如下日志,导致无法创建新的账号:
DEBUG - Account Exists (0.6ms) SELECT 1 AS one FROM `accounts` WHERE LOWER(`accounts`.`email`) = LOWER('[email protected]') LIMIT 1
DEBUG - (0.1ms) ROLLBACK
但是:
account = Account.create(:email => '[email protected]', :name => 'aijinsong', :password => 'aiajsajs', :password_confirmation => 'aiajsajs', :role => "admin")
这段代码执行后是成功的。日志如下:
DEBUG - (0.1ms) BEGIN
DEBUG - Account Exists (0.3ms) SELECT 1 AS one FROM `accounts` WHERE LOWER(`accounts`.`email`) = LOWER('[email protected]') LIMIT 1
DEBUG - SQL (0.2ms) INSERT INTO `accounts` (`blogs_count`, `comments_count`, `created_at`, `crypted_password`, `email`, `logo`, `name`, `profile_image_url`, `profile_url`, `provider`, `role`, `uid`) VALUES (0, 0, '2015-05-04 21:52:14', '$2a$10$7FoH64NjksN39nKI7gm7zu/36dlbgxWYpdn5590JWxjhlJersyN6W', '[email protected]', NULL, 'aijinsong', NULL, NULL, NULL, 'admin', NULL)
DEBUG - (0.5ms) COMMIT