2

これは最も奇妙なことです:

> User.count
   (74.7ms)  SELECT COUNT(*) FROM "users" 
 => 0 
2.0.0p0 :002 > User
 => User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, created_at: datetime, updated_at: datetime, name: string, confirmation_token: string, confirmed_at: datetime, confirmation_sent_at: datetime, unconfirmed_email: string) 
2.0.0p0 :003 > User.create(email: "abc@test.com", password: "test123", password_confirmation: "test123")
   (140.0ms)  BEGIN
  User Exists (543.7ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abc@test.com' LIMIT 1
   (0.3ms)  ROLLBACK
 => #<User id: nil, email: "abc@test.com", encrypted_password: "$2a$10$s7Ak0w04l3UixRqZbuvrJeLJb/AGD4FxQudSqcvYzDll...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: nil, updated_at: nil, name: nil, confirmation_token: nil, confirmed_at: nil, confirmation_sent_at: nil, unconfirmed_email: nil> 
2.0.0p0 :004 > User.all
  User Load (30.4ms)  SELECT "users".* FROM "users" 
 => [] 
> User.where(:email => "abc@test.com")
  User Load (24.8ms)  SELECT "users".* FROM "users" WHERE "users"."email" = 'abc@test.com'
 => [] 

何が起こっている?

Rails 3.2.13

編集 1

User.rbDevise と Rolify が付属するのと同じくらいバニラです。

class User < ActiveRecord::Base
  rolify
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable, :confirmable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :role_ids, :as => :admin
  attr_accessible :name, :email, :password, :password_confirmation, :remember_me

  has_one :store
#  has_many :items, 

end

編集 2

@ whit-kimmeyの提案に従って、私が試した別のこと:

> User.create!({email: "abc@test.com", password: "test123", password_confirmation: "test123"}, without_protection: true)
   (1.3ms)  BEGIN
  User Exists (105.5ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abc@test.com' LIMIT 1
   (0.3ms)  ROLLBACK
ActiveRecord::RecordInvalid: Validation failed: Password is too short (minimum is 8 characters)

編集 3

したがって、pw 8 の文字を作成すると、うまくいくように見えますが、これは奇妙です。しかし、それでも、そのメール アドレスを持つユーザーが既に存在するという理由には答えられませんか?

> User.create!({email: "abc@test.com", password: "test-123", password_confirmation: "test-123"}, without_protection: true)
   (0.2ms)  BEGIN
  User Exists (31.2ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'abc@test.com' LIMIT 1
  User Load (19.7ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = 'EZUGZPp8oEHMPSvExrgX' LIMIT 1
  SQL (742.6ms)  INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "last_sign_in_at", "last_sign_in_ip", "name", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "unconfirmed_email", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id"  [["confirmation_sent_at", Fri, 03 May 2013 17:47:43 UTC +00:00], ["confirmation_token", "EZUGZPp8oEHMPSvExrgX"], ["confirmed_at", nil], ["created_at", Fri, 03 May 2013 17:47:43 UTC +00:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "abc@test.com"], ["encrypted_password", "$2a$10$0VoGOKvWXhfpOVrut6S6QeM1lkPgOYfq9s4Oo6zg.VMHZoJWTbc8G"], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["name", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["unconfirmed_email", nil], ["updated_at", Fri, 03 May 2013 17:47:43 UTC +00:00]]
   (116.5ms)  COMMIT
 => #<User id: 1, email: "abc@test.com", encrypted_password: "$2a$10$0VoGOKvWXhfpOVrut6S6QeM1lkPgOYfq9s4Oo6zg.VMH...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, created_at: "2013-05-03 17:47:43", updated_at: "2013-05-03 17:47:43", name: nil, confirmation_token: "EZUGZPp8oEHMPSvExrgX", confirmed_at: nil, confirmation_sent_at: "2013-05-03 17:47:43", unconfirmed_email: nil> 
2.0.0p0 :008 > 
4

3 に答える 3

2

ユーザーがどこかに存在するとは言いません。ユーザーが存在するかどうかを知るために、ActiveRecord によって実行されるクエリを見ているだけです。実際のエラーを取得したい場合は、これを試してください:

> user = User.new(email: "abc@test.com", password: "test123", password_confirmation: "test123")
> user.valid?
> user.errors.full_messages
于 2013-05-03T17:52:02.123 に答える
0

検証を確認します。おそらく、名前またはその他の属性を検証しています。

于 2013-05-03T17:19:40.337 に答える