Devise Registration and Strong Parameters

This post is for Rails 4.x.

With Rails 4.x, control over accessible parameters have been shifted from the Model to the Control via strong params.

So how does one add new attribute fields to devise’s registration process? Maybe you’d like to add more user information.

It appears that the preferred way is to use devise’s very own helper to make the permit step easier. Instead of generating a custom devise controller just to permit the new fields, overload it via application_controller.

1. Create a before filter in your application_controller.
For a list of the default permissible attributes, click here.

<pre lang=”ruby’>

ie.

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

protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:email, :password, :password_confirmation, :birthday, :full_name) }
end
end
</pre>