我的表单是自己用 html 写的,没有 password 和 password_confirmation 字段 upate_attributes(params[:user]) 依然要验证 password 和 password_confirmation。 Rails 3.2.11
参考:http://ruby-china.org/topics/6719
#encoding: utf-8
class User < ActiveRecord::Base
attr_accessible :birthday, :homeplace, :name, :saysth, :secEmail, :sex, :password, :password_confirmation
has_secure_password
validates_presence_of :name, :message => "用户名不能为空!"
validates_presence_of :secEmail, :message => "登录邮箱不能为空!"
validates_presence_of :password, :message => "密码不能为空!"
validates_presence_of :password_confirmation, :message => "密码验证不能为空!"
validates_uniqueness_of :secEmail, :case_sensitive => false, :message => "该邮箱已经注册!"
validates :secEmail, :format => {:with => /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/, :message => "登录邮箱格式不正确!"}
validates :name, :length => {:maximum => 16, :too_long => "昵称太长!"}
validates :password, :length => {:minimum => 6,:maximum => 16, :too_short => "密码太短!",:too_long => "密码太长!"}
before_save {|user| user.secEmail = secEmail.downcase}
has_many :travels
end```