尝试更新 current_user
但在递减计数器属性并出现验证错误后无法保存,最小密码长度为 6 个字符 -</p>
current_user.crawl_counter -= 1
current_user.save!
更新:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :crawl_counter
PASSWORD_REGEX = /^[a-zA-Z\d]*$/
validates :password, format: { with: PASSWORD_REGEX, :message => I18n.t('errors.messages.password_invalid') }
end