class User < ActiveRecord::Base
before_validation :ensure_login_has_a_value
validates :login, :email, presence: true
protected
def ensure_login_has_a_value
if login.nil?
self.login = email unless email.blank?
end
end
end
为什么它有效但是
protected
def ensure_login_has_a_value
if login.nil?
#self.login = email unless email.blank?
# the change
login = email unless email.blank?
end
end
不工作??