一直提醒“用户名 不能为空字符,Signature 不能为空字符” 去掉 presence: true 后数据库中仍旧为空,遍查 stackoverflow,发现两个:
http://stackoverflow.com/questions/17256496/why-does-devise-keep-asking-me-that-the-name-cant-be-blank 情况也不相同,其中有一个似乎到最后都没有解决。。。
view:
<div class="control-group">
<label class="control-label">用户名</label>
<div class="controls">
<%= f.input :nickname, label: false %>
<div class="hint">请使用字母和数字,4位至10位</div>
</div>
</div>
<div class="control-group">
<label class="control-label">签名</label>
<div class="controls">
<%= f.input :signature, label: false %>
<div class="hint">test</div>
</div>
</div>
<div class="control-group">
<label class="control-label">E-mail</label>
<div class="controls">
<%= f.input :email, label: false %>
<div class="hint">请输入常用E-mail,便于登录和找回密码</div>
</div>
</div>
debug:
--- !ruby/hash:ActionController::Parameters
utf8: ✓
authenticity_token: et2G/Hl8K8qIdfJh6qszhG/bTotFDSnDpPqJMPHY8Zg=
member: !ruby/hash:ActionController::Parameters
nickname: lalala
signature: lalala
email: 1@2.com
password: lalala
password_confirmation: lalala
commit: 注册
action: create
controller: devise/registrations
member.rb
class Member < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
VALID_NICKNAME_REGEX = /\A[a-zA-Z\d]+/
validates :nickname, presence: true
# ,
# format: { with: VALID_NICKNAME_REGEX },
# length: { minimum: 4,maximum: 10 },
# uniqueness: { case_sensitive: false, message: "已被注册" }
validates :signature, presence: true
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
validates :email, presence: true,
format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false, message: "已被注册" }
validates :password, length: { minimum: 6 }
mount_uploader :avatar, AvatarUploader
STU_NUM_REGEX= /\A(\d[0-2][\d]{4}[2,9]\d{3})\z/
validates :student_number, length: { minimum: 10,maximum: 10 },
format: { with: STU_NUM_REGEX }, allow_blank: true
end