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

Can't get past Customizing Forms Section

I simply can't get this to work.

The problem is with full_name

first_name, last name, profile_name are not be input into my DB when I add a new user

Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"?", "authenticity_token"=>"ZB85voQDq+tEo7KD2a6Rw0ayowKqesSnN2lyNEBopdM=", "user"=>{"first_name"=>"Rick", "last_name"=>"Champlin", "profile_name"=>"rick", "email"=>"rickchamplin@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
Unpermitted parameters: first_name, last_name, profile_name
   (0.1ms)  begin transaction
  User Exists (0.1ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = 'rickchamplin@gmail.com' LIMIT 1
Binary data inserted for `string` type on column `encrypted_password`
  SQL (1.0ms)  INSERT INTO "users" ("created_at", "email", "encrypted_password", "updated_at") VALUES (?, ?, ?, ?)  [["created_at", Fri, 22 Nov 2013 22:55:50 UTC +00:00], ["email", "rickchamplin@gmail.com"], ["encrypted_password", "$2a$10$TxWxow6hBdo2qNPkO1kDV.AGBX1wb42nlIah9XfinUkwLhNnOiS4G"], ["updated_at", Fri, 22 Nov 2013 22:55:50 UTC +00:00]]
   (2.5ms)  commit transaction

This is what happens in terminal when I add a new user. None of the first_name, last_name, or profile_name are being committed to the DB.

Please help me figure it out!!

Here is the link to my work: https://github.com/rickimonius/treebook

1 Answer

Ok, I figured it out.

Apparently Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.

So in the application_controller.rb file I added

before_filter :configure_permitted_parameters, if: :devise_controller?

  protected

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

Which allows :first_name, :last_name, and :profile_name as inputs the user validly use.