ruby-on-rails – Rails 4 设计3.00rcpg注册编辑中的“未授权参数”

ruby-on-rails – Rails 4 设计3.00rcpg注册编辑中的“未授权参数”,第1张

概述我是Rails的新手 – 使用Rails 4 final和devise 3.0.0rc(rails 4兼容).我已正确配置并且注册工作正常,但是在某些时候我开始获取未经许可的参数:first_name,last_name在尝试创建新用户时出错(或编辑现有用户的配置文件).关于这个主题有一些类似的问题,但对于不支持的Devise版本 – 我的配置最初工作正常. Processing by Devis 我是Rails的新手 – 使用Rails 4 final和devise 3.0.0rc(rails 4兼容).我已正确配置并且注册工作正常,但是在某些时候我开始获取未经许可的参数:first_name,last_name在尝试创建新用户时出错(或编辑现有用户的配置文件).关于这个主题有一些类似的问题,但对于不支持的Devise版本 – 我的配置最初工作正常.

Processing by Devise::RegistrationsController#create as HTMLParameters: {"utf8"=>"✓","authenticity_token"=>"+DG4aeMPteQ4Mq9pPJ2JaitTVgp0NCW9nXi2qSv23zw=","user"=>{"first_name"=>"John","last_name"=>"Kenn","email"=>"[email protected]","password"=>"[FILTERED]","password_confirmation"=>"[FILTERED]"},"commit"=>"Sign Up"}Unpermitted parameters: first_name,last_name(0.2ms)  BEGINUser Exists (0.4ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = '[email protected]' liMIT 1(0.2ms)  RolLBACK

user.rb

class User < ActiveRecord::Base  has_many :jobrecords,dependent: :destroy  # after_create :send_welcome_email  # Include default devise modules. Others available are:  # :token_authenticatable,:encryptable,:confirmable,:lockable,:timeoutable and :omniauthable  devise :database_authenticatable,:registerable,:omniauthable,:recoverable,:rememberable,:trackable,:valIDatable  # Setup accessible (or protected) attributes for your model  valIDates :first_name,presence: true  valIDates :last_name,presence: true  valIDates :email,presence: true  attr_accessible :first_name,:last_name,:email,:password,:password_confirmation,:remember_me  def self.from_omniauth(auth)    where(auth.slice(:provIDer,:uID)).first_or_create do |user|      user.provIDer = auth.provIDer      user.uID = auth.uID      user.first_name = auth.info.nickname      user.last_name = auth.info.nickname    end  end  def self.new_with_session(params,session)    if session["devise.user_attributes"]      new(session["devise.user_attributes"],without_protection: true) do |user|        user.attributes = params        user.valID?      end    else      super    end      end  def password_required?    super && provIDer.blank?  end  def update_with_password(params,*options)    if encrypted_password.blank?      update_attributes(params,*options)    else      super    end  end  private    def send_welcome_email      UserMailer.signup_confirmation(self).deliver    endend

即使之前它正常工作,我尝试在registrations_controller.rb中覆盖sign_up_params,但这不起作用.我仍然可以使用openauth-twitter注册(因为应用程序在通过Twitter注册时不会要求姓或姓).任何帮助表示赞赏.

解决方法 所以,我不知道你是否已经尝试过这个,但我遇到了类似的问题,最后我将’configure_permitted_pa​​rameters’方法添加到我的ApplicationController中,并为:sign_up和:account_update添加了一个devise_parameter_sanitizer,每个设计文档: https://github.com/plataformatec/devise#strong-parameters

希望如果这不是您所需要的,它将使您朝着正确的方向前进.

总结

以上是内存溢出为你收集整理的ruby-on-rails – Rails 4 /设计3.00rc / pg注册/编辑中的“未授权参数”全部内容,希望文章能够帮你解决ruby-on-rails – Rails 4 /设计3.00rc / pg注册/编辑中的“未授权参数”所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1281458.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存