Edi Junior
Edi Junior

Reputation: 53

How to add custom devise fields/ Access devise default controller

I'm trying to use Devise gem in my project. That worked, but I still have a problem:

I setup devise in my application and generated the views, but I added an extra field in the database (username). So, the thing is that I need this username, but it's not being saved in the database when I create a new user :/ The problem seems to be in the controller, but I don't know how to access it.

Do devise hide its controllers? Can I access this controller and simply add the field I want in the params, for example? Do I really need to code a new controller that will override the default one? What should I do? and how?

Upvotes: 0

Views: 230

Answers (1)

Pragya Sriharsh
Pragya Sriharsh

Reputation: 559

See doc: https://github.com/plataformatec/devise

You have to tell the devise to save extra parameters in the DB.

Your application_controller.rb file look like:

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

    protected

    def configure_permitted_parameters
        devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
    end
  end

Upvotes: 0

Related Questions