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 Generating the Devise Views

The first_name and last_name are not being registered in my user model

I added the first_name and last_name fields to the device migrate file, but when I create a new user (and inspect it using rails console) the fields for first_name and last_name are still Nill.

Any idea what might be going on here?

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You're probably using Rails 4 and the course uses Rails 3.2 (it's very old). Whenever you introduce new fields to the models and want them to be editable through forms, you have to whitelist them. This video explains it nicely: http://www.lynda.com/Ruby-Rails-tutorials/Mass-assignment-strong-parameters/139989/159116-4.html

With Devise it's more complicated because there is no overt user controller to put user_params in. Go to devise documentation: https://github.com/plataformatec/devise and scroll down to Strong Parameters section to see how it's done. In your case you should probably add this to your Application controller:

  before_action :configure_permitted_parameters, if: :devise_controller?


  def configure_permitted_parameters
    devise_parameter_sanitizer.for(:sign_up) << :first_name << :last_name
    devise_parameter_sanitizer.for(:account_update) << :first_name << :last_name

This should allow you to create and edit users properly now. Strong Parameters is something that you will deal with all the time in Rails 4 apps, so make sure you understand the topic thoroughly.

Note: this course may difficult for you if you're using the newest versions of Rails and other gems. A lot of this is deprecated, some of the gems changed, some are not even maintained anymore.

Yeah! This worked great. Thank you so much!

I am aware that this course might be too outdated, but I am on the Ruby track and I was very confused on the Build a To Do List Application with rails, I think they skip a lot of important parts that are covered in this course. But thanks anyway for the heads up and for your quick response!