ActiveModel:創(chuàng)建新用戶(hù)時(shí)的ForbidenAttributesError我在Ruby中有這個(gè)模型,但是它拋出了一個(gè)ActiveModel::ForbiddenAttributesErrorclass User < ActiveRecord::Base
attr_accessor :password
validates :username, :presence => true, :uniqueness => true, :length => {:in => 3..20}
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, :uniqueness => true, format: { with: VALID_EMAIL_REGEX }
validates :password, :confirmation => true
validates_length_of :password, :in => 6..20, :on => :create
before_save :encrypt_password
after_save :clear_password def encrypt_password if password.present?
self.salt = BCrypt::Engine.generate_salt self.encrypted_password= BCrypt::Engine.hash_secret(password, salt)
end
end
def clear_password self.password = nil
endend當(dāng)我運(yùn)行這個(gè)動(dòng)作 def create @user = User.new(params[:user])
if @user.save
flash[:notice] = "You Signed up successfully"
flash[:color]= "valid"
else
flash[:notice] = "Form is invalid"
flash[:color]= "invalid"
end
render "new"
end在……上面ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux].你能告訴我如何消除這個(gè)錯(cuò)誤或建立一個(gè)適當(dāng)?shù)挠脩?hù)登記表嗎?
ActiveModel:創(chuàng)建新用戶(hù)時(shí)的ForbidenAttributesError
阿波羅的戰(zhàn)車(chē)
2019-07-17 09:31:47