2
votes

I've been recently working on a user's account update using Devise, what I'm trying to do is permit parameters that are needed for the update. I did it before for sign_up by permitting parameters like so:

#application_controller.rb
def configure_permitted_parameters
     devise_parameter_sanitizer.for(:sign_up) << :nombre << :apellido
    end

Now, that works like a charm for when a user signs up and I thought that I could do the same to edit the user's information, so I did the following:

#application_controller.rb
def configure_permitted_parameters
     devise_parameter_sanitizer.for(:edit)  << :genero << :estatura << :ciudad_id << :foto << :nombre << :apellido
    end

Surprisingly this didn't work and I don't know why. I did the exact same as I did before and nothing happened. So then I started searching for different ways to edit the user's information, did what palaformatec recommends to do and even looked at various questions here but I couldn't find an answer.

My registrations_controller.rb looks like this:

#registrations_controller.rb
    class RegistrationsController < Devise::RegistrationsController

def update

    self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
    prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
    resource_updated = update_resource(resource,account_update_params)
    yield resource if block_given?
    if resource_updated
        if is_flashing_format?
            flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
            :update_needs_confirmation : :updated
            set_flash_message :notice, flash_key
        end
        sign_in resource_name, resource, bypass: true
        respond_with resource, location: after_update_path_for(resource)
    else
        clean_up_passwords resource
        respond_with resource
    end
end

protected

    def params
        params.require(:user).permit({:fecha_nacimiento=>[]},:nombre,:apellido,:ciudad_id,:foto,:genero,:estatura)
    end

    def account_update_params
        devise_parameter_sanitizer.for(:account_update) << {:fecha_nacimiento => []} << :genero << :estatura << :ciudad_id << :foto << :nombre << :apellido
    end
    def update_resource(resource,params)
        resource.update_without_password(params)
    end

end

I really don't know what else to do, I asked friends too and no one knows what happens. I know that a stack level too deep appears when an infinite loop is present, but neither me nor my friends have managed to identify what's causing it.

If you need any more information I'll edit the question and add it for you.

Thank you all in advance.

1

1 Answers

2
votes

This bit of code is the one causing the Stack level too deep error:

def params
  params.require(:user).permit({:fecha_nacimiento=>[]},:nombre,:apellido,:ciudad_id,:foto,:genero,:estatura)
end

As long as you use the method name inside the method itself, you are making your method call itself recursively until ... boom! Rename your method name:

def update_params
  params.require(:user).permit({:fecha_nacimiento=>[]},:nombre,:apellido,:ciudad_id,:foto,:genero,:estatura)
end

and you should be fine.