Devise error: email can’t be blank

Devise error: email can’t be blank? – Well it isn’t!

Many of you might have been frustrated with the Devise error: email can’t be blank.

You do indeed type an email in the text field but still get this error! I even took out the :validatable module from devise in order to get rid of this error. However that is not the solution.

The Rails 4 uses strong-parameters is causing this issue and the solution is simple

The solution is simple. You just have to place this code segment into your Application Controller (application_controller.rb):

  before_filter :configure_permitted_parameters, if: :devise_controller?

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
end

Keep in mind to configure for each action like :sign_in, :sign_up, :account_update etc by doing something like: (if it is of course needed for the other actions as well)

def configure_permitted_parameters
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:username, :email, :password, :password_confirmation) }
  devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:username, :email, :password, :password_confirmation) }
  devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:username, :email, :password, :password_confirmation) }
end

Discussions — No responses yet