Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

How do I make custom fields save with a devise created user table?

Hi I am adding new columns to my devise user generated table in rails. Now the users/new and users/edit have the new fields. However in the rails console, the new fields are nil. I still have a blank model which may be the problem The other issue may be in application controller . I have followed the instructions from http://www.peoplecancode.com/tutorials/adding-custom-fields-to-devise regarding adding code to the application controller, however, I am getting this error in the server: undefined method `before_filter' for ApplicationController:Class Did you mean? before_action

Brian Gilbank
Brian Gilbank
9,586 Points

Without looking at your link, you probably need to white list your new devise fields.

This is what I do:

Open your application controller and add: include DeviseWhitelist

class ApplicationController < ActionController::Base
  protect_from_forgery with: :exception
  include DeviseWhitelist
end

Now go to controller/concerns and add a new file called devise_whitelist.rb

module DeviseWhitelist 
extend ActiveSupport::Concern 

 included do 
  before_filter :configure_permitted_parameters, if: :devise.controller? 
end 

def configure_permitted_parameters 
 devise.parameter.sanitzier.permit(:sign_up, keys: [:first_name, :last_name, :about, :type]) 
 devise.parameter.sanitzier.permit(:account_update, keys: [:first_name, :last_name, :about, :type]) 
end  

end

Above you can see my custom devise fields: :first_name, :last_name, :about, :type. You can just replace it with your fields, but you need to do it for both sign up and account update.

Sandra Hogan
Sandra Hogan
8,657 Points

before_action is just a new syntax for before_filter. Also I agree with Brian Gilbank about making sure you have whitelisted your devise fields.

1 Answer

OH Thank you! I will try it asap! can tell this will be helpful knowledge to know anyway!