ruby-on-railsdeviseruby-on-rails-4attr-accessiblestrong-parameters

Custom user fields in Devise 3 under Rails 4


I'm using the release candidate of Devise 3 so that I can use it with Rails 4. In Rails 3.2 I used to be able to add a custom field to my User model by simply adding that field to the registration/edit.html.erb and registration/new.html.erb files (after running the proper migration). Then I'd just add that field to the attr_accessible list of fields in the model.

However, in Rails 4, there is no attr_accessible list and I can't simply add fields in the views. How do I add custom User fields?


Solution

  • I was told to look in the main README on the github page and there it was. Easy.

    class ApplicationController < ActionController::Base
      before_filter :configure_permitted_parameters, if: :devise_controller?
    
      protected
    
      def configure_permitted_parameters
        devise_parameter_sanitizer.for(:sign_up) << :username
      end
    end