第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

ActiveModel:創(chuàng)建新用戶時(shí)的ForbidenAttributesError

ActiveModel:創(chuàng)建新用戶時(shí)的ForbidenAttributesError

蕪湖不蕪 2019-07-27 15:14:28
ActiveModel:創(chuàng)建新用戶時(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ù)挠脩舻怯洷韱幔?
查看完整描述

3 回答

?
繁星coding

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超4個(gè)贊

如果使用ActiveAdmin,請(qǐng)不要忘記在模型寄存器塊中也有一個(gè)許可證_params:

ActiveAdmin.register Api::V1::Person do
  permit_params :name, :address, :etcend

這些需要與控制器中的設(shè)置一起設(shè)置:

def api_v1_person_params  params.require(:api_v1_person).permit(:name, :address, :etc)end

否則,您將得到錯(cuò)誤:

ActiveModel::ForbiddenAttributesError



查看完整回答
反對(duì) 回復(fù) 2019-07-28
  • 3 回答
  • 0 關(guān)注
  • 343 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)