Tuma
Tuma

Reputation: 807

"Undefined method `concat'" on "devise_parameter_sanitizer.permit"

I'm writing a custom sign-up devise controller, and I'm having trouble adding permitted params due to this error (this is the output from Rspec, but the same error happens manually):

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

The full controller:

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

At first glance it seems like a bug in the gem, but no one seems to have this issue - google returns nothing relevant. Is this an error in my code?

Upvotes: 1

Views: 1371

Answers (1)

Paulo Belo
Paulo Belo

Reputation: 4437

I'm not sure if it was the case, but this error can occur if you duplicate the parameters sanitizer, like using it in users controller but also in application controller.

You can see a more detailed explanation here: GitHub issue closed

Upvotes: 3

Related Questions