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 Updating the User Model

Now that attr_accessible is not valid, in Rails 4. How should we modify the code

I have modified the device user migration, added first_name, last_name and profile_name, modified the devise views, so that it will be able to accomodate the above fields. But I am unable to the attr_accessible, since it is not allowed, so first_name, last_name and profile_name are going to nil in the console. Any help will be greatly appreciated. Thanks

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :token_authenticatable, :confirmable,
  # :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :email, :password, :password_confirmation, :remember_me
  # attr_accessible :title, :body

1 Answer

You wouldn't use attr_accessible or attr_ anything in Rails 4. But really, dude, your first port of call should be google. And there is plenty there is you just google "Rails 4 attr_accessible": https://www.google.es/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=rails%204%20attr_accessible

Anyway the thing is .. what I am asking is specific to devise. I know that rails 4 has params.permit thing. I figured out somehow .. you should override a method in controller .. `class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller?


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


Did it work? If so, good job!