Override Devise Controller with Custom Fields and Strong Parameters

So I already wrote a post on how to override the Devise Controller.  In this case I’ve added a field to the User model during the development process, however I need to add that field to the white list for strong parameters so that it can be edited and updated from the views.  This is normally done in the controller, however it can be a bit trickier when we are overriding or customizing the Devise controller.

After searching around and reading several different ideas, this is what worked for me.

Add a function in the normal application_controller.rb, where we specifically permit our new User model fields.

Screen Shot 2014-09-05 at 7.15.03 AM

 

So here we create a function configure_permitted_parameters that adds my custom fields, in this case :name and :certificate to the white list for new users singing up and for updated or editing their accounts.

We then create a before_filter to only call this function in the devise controller.  Pretty simple right?

The device documentation mentions this function here. Another resources is this StackOverflow question.

Credit also to this gist, although it didnt work directly for me until I put the code in the application controller.

Advertisements