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

Kurt Lopez
PLUS
Kurt Lopez
Courses Plus Student 4,455 Points

No attr accessible in user.rb? didn't get the message for first_name, last_name, profile_name either

No attr accessible in user.rb? didn't get the message for first_name, last_name, profile_name either

5 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'm not sure what you're asking about. But just in case: be aware that you're doing a Rails 3 course (treebook). If you're using Rails 4 or above, you will have a bad time and attr_accessible in general will not work at all. Either move to Todo List course or downgrade your Rails to version 3.2.

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

Add following to your ApplicationController:

class ApplicationController < ActionController::Base
  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) }
  end
end
James demby
James demby
10,296 Points

By this do you mean replace my ApplicationController with this?

There is already a class there.

James demby
James demby
10,296 Points

When I try to preview my app after adding this I get

/home/action/workspace/Text_List_App/Text_lists/app/controllers/application_controller.rb:10: syntax error, unexpected '.', expecting ';' or '\n' ...ers devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(... ... ^ /home/action/workspace/Text_List_App/Text_lists/app/controllers/application_controller.rb:13: syntax error, unexpected keyword_end, expecting end-of-input

I'm using Rails 4 (as of yesterday) and when I tried to add the attr_accessible element (along with the first_name, last_name and profile_name modules), I received an error.

After restarting the server and removing the element along with its modules, I was able to sign in no problem. I'm guessing those attributes have been included by default behind the scenes. Not sure, but works!

Same stuff here, I'm using Rails 4, can I downgrade it in the middle of the course now? I was really into doing this course...

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'm not sure it's possible. The 'guts' of Rails changed a lot between these two versions.

So the only rails compatible course on treehouse are the ones that rails < 4.0.0?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Treebook is an older course and you need Rails 3.2 to follow along. Treehouse has another, newer course, the Todo Application (ODOT), look in the courses library. It uses Rails 4.0. It is slowly getting old as well, but the newest Rails should work with it. It's always the best idea to just download the first stage project files and work on it, this way we're always using the proper versions of gems and Rails is a gem.