奇怪的Devise创建用户数据库连接

时间:2014-12-09 13:21:06

标签: ruby-on-rails postgresql ruby-on-rails-4 devise

我发现以下数据库连接非常奇怪:

Started POST "/users" for 127.0.0.1 at 2014-12-09 21:08:10 +0800
Processing by UsersController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"RfHtAnEp8YkhMU=", "user"=>{"name"=>"Jason", "email"=>"bb@cc.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
   (0.1ms)  BEGIN
  User Exists (0.4ms)  SELECT  1 AS one FROM "users"  WHERE "users"."email" = 'bb@cc.com' LIMIT 1
  User Exists (0.3ms)  SELECT  1 AS one FROM "users"  WHERE LOWER("users"."email") = LOWER('bb@cc.com') LIMIT 1
  SQL (0.3ms)  INSERT INTO "users" ("created_at", "email", "encrypted_password", "name", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id"  [["created_at", "2014-12-09 13:08:10.904314"], ["email", "bb@cc.com"], ["encrypted_password", "$2a$10$ExmT7uQlTfda.zr0wQPvKdhdpn.SWV8C"], ["name", "Jason"], ["updated_at", "2014-12-09 13:08:10.904314"]]
   (8.2ms)  COMMIT
Redirected to http://localhost:3000/admin/index
Completed 302 Found in 98ms (ActiveRecord: 9.4ms)

控制器是新创建的控制器,而不是默认的设计控制器,我从用户模型中删除了:可注册模块。

class UsersController < ApplicationController
  def index

  end

  def new
    @user = User.new
  end

  def create
    @user = User.create!(user_params)
    redirect_to admin_index_path
  end
end

编辑:我添加了以下验证:

 validates_presence_of :email
 validates :name, length: { in: 1..28}
 validates_uniqueness_of :email, :case_sensitive => false

我只是想知道为什么在SQL INSERT之前有两个“用户存在”连接?这是正常的吗?

0 个答案:

没有答案