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

ruby.rb
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
end

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?

protected

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

end`

Did it work? If so, good job!