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

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
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?


  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :profile_name, :email, :password, :password_confirmation, :avatar) }
Roberto Alicata
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.