7
私はRailsチュートリアルの1つを行っていますが、ユーザ検証のセクションでは、ユーザの編集/作成時にパスワード確認を空白にすることはできません。以前の回答を見て、attr_accessibleを使用した人のように見えましたが、これはレールから取り除かれました。私はトータル・レール/ウェブ・デベロッパーですので、どうやって進めるか分かりません。ビューはハムにあります、それは悪い習慣であれば申し訳ありません。あなたの使用して、レール4以来rails 4パスワード確認ca
モデル
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
attr_accessor :name, :email
validates_confirmation_of :password
has_secure_password
validates :name, presence: true, length:{ maximum: 16 }
VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
has_one :profile
has_many :posts
end
ビュー
= form_for(@user) do |f|
- if @user.errors.any?
#error_explanation
%h2
= pluralize(@user.errors.count, "error")
prohibited this username from being saved:
%ul
- @user.errors.full_messages.each do |msg|
%li= msg
.field
= f.label :name
= f.text_field :name
.field
= f.label :email
=f.text_field :email
.field
= f.label :password
= f.password_field :password
= f.label :password_confirmation
= f.password_field :password_confirmation
.actions
= f.submit
:
これは、レール4の新機能ですか? (テストを実行しているとき、または自分でテストしたとき)、後者がコントローラコードを投稿できるかどうかを確認します。 – wpp