저는 Michael Hartl의 튜토리얼 (6 장)을 작업 중입니다. 나는 레일 콘솔에서 새 사용자를 만들려고 할 때 :레일 튜토리얼 User.save
user = User.new(name: "Lord of Darkness", email: "[email protected]")
내가 얻을 :
=> #<User id: nil, name: "Lord of Darkness", email: "[email protected]",
created_at: nil, updated_at: nil, password_digest: nil>
올바른 것 같다. 하지만 내가 이걸 구하려고하면 :
irb(main):007:0> user.save
←[1m←[36m (0.0ms)←[0m ←[1mbegin transaction←[0m
←[1m←[35mUser Exists (0.0ms)←[0m SELECT 1 AS one FROM "users" WHERE LOWER("us
ers"."email") = LOWER('[email protected]') LIMIT 1
←[1m←[36m (0.0ms)←[0m ←[1mrollback transaction←[0m
=> false
나는 확실히 원하는 것이 아니다. 내 user_spec이 모든 테스트를 통과했습니다. 내 user.rb은 다음과 같습니다
class User < ActiveRecord::Base
attr_accessible :email, :name, :password, :password_confirmation
has_secure_password
before_save { |user| user.email = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, presence: true, length: { minimum: 6 }
validates :password_confirmation, presence: true
end
이이 문제를 저장의 원인은 무엇?이 오류를 해결하지 않고서는 튜토리얼을 진행할 수 없습니다.
checkout user.valid? 또는 그것은 이메일 ID가 존재하는 것 같습니다, 체크 아웃 user.errors.messages 또는 full_messages, – Amar
나는 UserCreate() * UserSave() * – Raghuveer
@Amar가 제안한 유효성 검사 오류를 확인합니다. , 당신은 그것을 추적 할 수 있어야합니다 – Bijendra