"devise_parameter_sanitizer.permit "上的 "Undefined method `concat'"

问题描述 投票:1回答:1

我正在写一个自定义注册 devise 控制器,由于这个错误,我在添加允许的参数时遇到了麻烦(这是Rspec的输出,但同样的错误也会手动发生)。

Failure/Error: devise_parameter_sanitizer.permit(:sign_up, keys: [:nome, :password, :password_confirmation, :cnpj, :razao_social, :nome_fantasia, :email, :tipo_entidade_id])

 NoMethodError:
   undefined method `concat' for #<Proc:0x0055ca9fb2d850>
   Did you mean?  concern

完整的控制器

class Users::RegistrationsController < Devise::RegistrationsController
 before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]

  # POST /resource
  def create
    user_params     = sign_up_params[:user_params]
    entidade_params = sign_up_params[:entidade_params]

    if !(User.exists?(email: user_params[:email]) || Entidade.exists?(cnpj: entidade_params[:cnpj]))
      @entidade = Entidade.new(entidade_params)
      @entidade.data_validade = 30.days.from_now

      if @entidade.save
        @user = User.new(user_params)
        @user.entidade_id = @entidade.id
        if @user.save
          flash[:notice] = 'Usuario criado com sucesso.'
          redirect_to root_path
        end
      end
    end
  end
  protected

  # If you have extra params to permit, append them to the sanitizer.
  def configure_sign_up_params
    devise_parameter_sanitizer.permit(:sign_up, keys: [:nome, :password, :password_confirmation, :cnpj, :razao_social, :nome_fantasia, :email, :tipo_entidade_id])
  end
end

乍一看,这好像是gem中的一个bug,但似乎没有人有这个问题 - google没有返回任何相关的内容。这是我代码中的错误吗?

ruby-on-rails ruby rspec devise
1个回答
1
投票

我不确定是否是这种情况,但如果你重复使用参数消毒器,比如在用户控制器中使用它,但在应用程序控制器中也使用它,就会出现这个错误。

你可以在这里看到更详细的解释。GitHub问题已关闭

© www.soinside.com 2019 - 2024. All rights reserved.