-1
我尝试在Rails4中进行确认验证,但它无法正常工作。 当我提交表单的消息是“电子邮件确认不能为空”,而不是“邮件不匹配确认” 这里是我的代码:Rails验证 - 确认不正确
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',并且在场验证会给出“不能空白”的消息。 –
<%= f.text_field :email %>