Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Build a Simple Ruby on Rails Application Creating an Authentication System Migrating Statuses

When registering :first_name, :last_name and :profile_name are not getting inserted into db

my migrations are update and the :first_name, :last_name and :profile_name columns are created in the user table. But, when I rails s and head over to register a new user and fill in all fields and hit submit, the :email and :password_encrypted get inserted, but not the :first_name, :last_name and :profile_name. Any thoughts.

4 Answers

Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

in Rails4 add this code in app/controllers/application_controller.rb:

  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation, :avatar) }
  end 
Roberto Alicata
PLUS
Roberto Alicata
Courses Plus Student 39,959 Points

Check if you update the permitted parameters on the User controller (this is because of the Rails 4 Strong Parameters)

Questions: The User controller you speak of should be in this directory correct?treebook>app>controllers>users_controller.rb

If so, I don't have one and need to generate; Could I adjust the application_controller.rb? and put the code there.

Any thoughts on what the three lines of code should look like.

Thanks so much for your help.

Artem Prytkov
Artem Prytkov
11,932 Points

What version of Rails you use (3.2 and 4 have different approach to security) I assume you are modifing existing registation with 3 new fields. If so, you are already have all required controllers.

So you have to allow these fields in your registration controller.

You might also wnat to test if you can create user (i.e. your model specification allows you) with new fields via console.