Search code examples
ruby-on-railsdevisestrong-parameters

Rails 4 + Devise 3.0.0 Adding Username


I'm working with Rails 4 and Devise 3.0.0 and am new to using these new strong paramters. I added a username to the User model using the documentation on the Devise wiki. The problem I'm running into is the strong parameters change in Rails 4.

How do I add the :login attribute to the user model to enable logging in with either the username or email?


Solution

  • From the rails4 readme on devise: https://github.com/plataformatec/devise/tree/rails4#strong-parameters

    class ApplicationController < ActionController::Base
      before_filter :configure_permitted_parameters, if: :devise_controller?
    
      protected
    
      def configure_permitted_parameters
        devise_parameter_sanitizer.for(:sign_in) { |u| u.permit(:login, :email) }
      end
    end