recently read railstutorial .
the model generated through rails g model User name:string email:string
has gradually become the following virtues with the tutorials:
class User < ApplicationRecord
before_save { self.email = email.downcase }
validates :name, presence: true, length: { maximum: 50 }
-sharpVALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
end
what is the meaning of self.email
, email
and : email
in this code, and what"s the difference?
if you change validates: email,.
to validates self.email,.
after
, why do you report NoMethodError: NoMethodError: undefined method "email"
?