gpt4 book ai didi

ruby-on-rails - rails 4密码确认ca

转载 作者:数据小太阳 更新时间:2023-10-29 06:58:28 26 4
gpt4 key购买 nike

我正在阅读其中一个 Rails 教程,在用户验证部分,我不断收到错误消息,告诉我在编辑/创建用户时我的密码确认不能为空。我查看了以前的答案,看起来人们使用的是 attr_accessible,它已脱离 rails 。我是一个完全的 rails/web 开发新手,所以我不确定如何进行。 View 是在 HAML 中,如果这是不好的做法,我们深表歉意。

型号

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+\-.]+@[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

最佳答案

自从您使用 Rails 4 以来,请查看您的强参数设置并确保允许 password_confirmation。

这是 rails 4 中的一个新特性: http://edgeapi.rubyonrails.org/classes/ActionController/StrongParameters.html

关于ruby-on-rails - rails 4密码确认ca,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19547452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com