RUBY_ON_RAILS - registrations_controller.Rb - I can’t resolve the user registration permission bug!

Asked

Viewed 30 times

1

Method create:

 def create
 # super
 build_resource(sign_up_params)

Permission method:

def sign_up_params

         params.require(:usuario).permit(:nome, 
                                          :email,
                                          :password, 
                                          :password_confirmation,
                                          :possui_planejador,
                                          :profissional_id,
                                          :tipo_profissional,
                                          :nome_escritorio,
                                          :subdominio_escritorio,
                                          :tipo,
                                          :especialidade => [],
                                          perfil_attributes: [
                                            :id,
                                            :avatar,
                                            :origem,
                                            :cpf,
                                            :cidade,
                                            :estado,
                                            :profissao,
                                            :nome,
                                            :telefone,
                                            :data_nascimento,
                                            {:certificacao_ids => []}
                                          ])
end

Whenever I wear rails s to climb the server, it error in the method permit. I have tried many things and I don’t know what to do. The version of Rails is the 5.1.0, ruby 2.3.0.

It is a user registration system, when creating a user, other tables are also created, as the user profile.

I’m using the Gem binding.pry to debug and the devise for authentication.

Can someone help me?

Error that appears:

Nomethoderror (Undefined method `Permit! ' for #Array:0x0055993ffdb370 Did you Mean? permutation): app/controllers/api/v1/registrations_controller.Rb:201:in 'sign_up_params'

1 answer

2

You tried to use the method configure_permitted_parameters that the Visa documentation? https://github.com/heartcombo/devise#Strong-Parameters

I believe I can solve your problem. Just put in the Applicationcontroller something like this:

class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:nome, 
                                      :email,
                                      :password, 
                                      :password_confirmation,
                                      :possui_planejador,
                                      :profissional_id,
                                      :tipo_profissional,
                                      :nome_escritorio,
                                      :subdominio_escritorio,
                                      :tipo,
                                      :especialidade => [],
                                      perfil_attributes: [
                                        :id,
                                        :avatar,
                                        :origem,
                                        :cpf,
                                        :cidade,
                                        :estado,
                                        :profissao,
                                        :nome,
                                        :telefone,
                                        :data_nascimento,
                                        {:certificacao_ids => []}
                                      ]])
  end
end

I hope I’ve helped.

EDIT: I believe that you don’t even need to put the default attributes of E-mail, password and password_confirmation in this hash

Browser other questions tagged

You are not signed in. Login or sign up in order to post.