我不明白为什么模型没有检查密码确认,以下是该模型的代码:
class User < ActiveRecord::Base
attr_accessor :password_confirmation
validates :email, :presence =>true,
:uniqueness=>true
validates :password, :presence =>true,
:length => { :minimum => 5, :maximum => 40 },
:confirmation =>true
validates_confirmation_of :password
end
控制器的作用是从视图中接收数据并尝试执行保存操作,以下是视图的代码:
<h1>Registration process</h1>
<%= form_for(@new_user) do |f|%>
<% if @new_user.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@new_user.errors.count, "error") %> prohibited this article from being saved:</h2>
<ul>
<% @new_user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<%= f.label :email %><br />
<%= f.text_field :email %><br />
<%= f.label :password %><br />
<%= f.password_field :password %><br />
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation %>
<%#TODO Confirm password%>
<%= f.submit 'Join' %>
<%end%>
如果密码不匹配,不会出现任何错误。
:confirmation => true
。 - davemyron