Validatoren, Passwortbestätigung

Ich nicht herausfinden können, warum das Modell doesen ' T check für die Bestätigung des Passworts, das ist der code des Modells:

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

Controller soll die Daten aus der view und führen Sie ein sparen, das ist der code der Ansicht:

<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%>

Keine Fehler kommen, wenn das Passwort nicht übereinstimmt.

Kommentar zu dem Problem - Öffnen
Der obige code funktioniert für mich. Kommentarautor: Chamnap
Brauchst du die doppelte Bestätigung der Validierung? Geben Sie :Bestätigung => true in das Passwort-Validierung. Kommentarautor: davemyron
Ja...der code funktioniert bei mir auch (wie Chamnap sagte) und mit einer Doppel-password_confirmation validator sollte nicht der Grund dafür sein, nicht zu arbeiten., es wäre einfach geben Sie zweimal die Meldung "Passwort nicht mit der Bestätigung überein" Kommentarautor: Daniel

InformationsquelleAutor der Frage Joe | 2011-01-15

Schreibe einen Kommentar