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

Stephen Johnson
Stephen Johnson
8,448 Points

Trouble With attr_accessible

I Get an error when i am trying to add user_id to the status.rb! I am on ruby 4 and stuck

NoMethodError in StatusesController#index

2 Answers

I believe I had the similar error. You need to add the gem 'protected_attributes' to your Gemfile.

Denny Ku
PLUS
Denny Ku
Courses Plus Student 7,437 Points

That's because attr_accessible doesn't work on Rails4 anymore. Those will work on controller. You can try that add these codes to the bottom of "app/controllers/application_controller.rb"

 before_filter :configure_permitted_parameters, if: :devise_controller?

   protected
   # Devise using strong parameters . (lazy way!)
   def configure_permitted_parameters
     devise_parameter_sanitizer.for(:sign_up)  { |u| u.permit(:first_name,:last_name,:profile_name,:email, :password) }
     devise_parameter_sanitizer.for(:account_update) { |u| u.permit(:first_name,:last_name,:profile_name,:email, :password) }
   end

and don't forget to change add user_id in the"app/controllers/statuses_controller.rb" Like this:

params.require(:status).permit(:user_id,:name, :content)

This problem really bothers me then, it's hard to figure out how to solve this, but I suggest you can search "Strong Parameter", on "Devise" github page, solve this problem and keep going on, soon you will understand what's going on.