は私がまさにそのパスワードとpassword_confirmation一致を検証するために、私のユーザー登録フォームを取得して助けが必要な作業ではないpassword_confirmation。Railsは
現在の形では、パスワードに入力されたデータは、データベース内のフィールドを消化通過し、password_confirmationフィールドに任意の入力を受け入れますし、すべてのエラーを与えることはありません。
私のコードは以下の通りです。
モデル - user.rb
class User < ApplicationRecord
before_save { self.email = email.downcase }
#attr_accessible :user_name, :email
validates_confirmation_of :password
has_secure_password
validates :user_name, presence: true, length: { maximum: 25 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 }, format: { with: VALID_EMAIL_REGEX }
validates :password, presence: true, confirmation: true, length: { minimum: 6 }
has_many :trips
has_many :countries, through: :trips
end
ビュー -
<div class="container">
<h1 class="text-center" style="margin-top: 10px;" >Sign up</h1>
<div class="row">
<div class="col-md-6 offset-md-3 ">
<%=form_for(@user) do |f| %>
<%= render 'shared/error_messages' %>
<div class="form-group">
<%= f.label :user_name, "Username" %>
<%= f.text_field :user_name, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation, "Password Confirmation" %>
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>
<div class="form-group">
<%= f.submit "Create an account", class: 'form-control btn btn-primary' %>
</div>
<% end %>
</div>
</div>
</div>
new.html.erbは私も持っている私のgemfileで-v 3.1.7 bcryptの。他の情報が必要な場合は、私に知らせてください。私は喜んで提供します。
あなたのテーブルでpassword_digest列を持っていますか? – hashrocket
あなたのコントローラーはどうですか?私の許可でpassword_confirmation: – Yana