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 Customizing Forms Creating Relationships

user.rb has undefined method

I deleted it previously because it was giving me errors. Here's the line of code in user.rb that is included in the video.

attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name

This is the error message that I get.

undefined method `attr_accessible' for #<Class:0x462ad40>

2 Answers

Seph Cordovano
Seph Cordovano
17,400 Points

I'm also using rails 4.

My application controller finally looked like this after quite a number of hours of debugging this is issue and not much help from the Treehouse forums. Replace (:profile_name, :email, :first_name, :last_name, :password) with whatever you have in yours.

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
before_filter :update_sanitized_params, if: :devise_controller?

   protect_from_forgery with: :exception 

end

def update_sanitized_params
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:profile_name, 
    :email, :first_name, :last_name, :password) }
end
Nick Fuller
Nick Fuller
9,027 Points

It sounds like you're using Rails 4 and the video is for Rails 3. attr_accessible was removed from rails 4