【发布时间】:2016-06-17 13:36:08
【问题描述】:
我正在尝试在 Rails4 中进行确认验证,但它不能正常工作。 当我提交表单时,消息是“电子邮件确认不能为空”而不是“电子邮件与确认不匹配” 这是我的代码:
enter code here
#model user.rb
class User < ActiveRecord::Base
validates :email, confirmation: true
validates :email_confirmation, presence: true
end
#view
<div class="field">
<%= f.label :email_confirmation %><br>
<%= f.text_field :email_confirmation %>
</div>
#controller
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
【问题讨论】:
-
email的字段在哪里?我在这里只能看到email_confirmation...并且存在验证将给出“不能为空白”的消息。 -