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 trialHugo Jenkins
1,860 PointsAdding attr_accessible causes crash
Hey guys. When I add attr_accessible to status.rb, my application crashes and gives this error:
undefined method `attr_accessible' for #<Class:0x00000102fd7368>
...with line 2 of status.rb highlighted. I'm not really sure how to troubleshoot this - RoR is still pretty unknown to me.
As an aside, I'm finding this track is going past pretty quickly, it's been tough to follow in parts.
If anyone has an idea about what I might be missing, that would be very helpful!
Cheers Hugo
2 Answers
John Steer-Fowler
Courses Plus Student 11,734 PointsHey Hugo,
There have been a lot of threads on this topic. Here is one of the ones that explains your issue a bit: Attr_accessible Issue
Just to let you know that since Rails 4.0, attr_accessible is no longer supported directly with rails, but as mentioned in that linked topic, you can get a gem to support it if you wish.
I recommend following the Creating a Todo List Application courses from Treehouse as they were made specifically for Rails 4.
If you want to continue to follow the course you are on to make the Social Network, you could install that gem, or even better, revert to the same version of Rails used in that course (Rails 3.2.13)
Hope this helps
Joshua Jarvis
6,457 PointsActually you don't need to install a Gem to do this. In Rails 4 you can go into your statuses.rb controller file and 'permit' user_id to be added. My problem was that the form was not permitting me to save :user_id and therefore there was no way to match the the users table. I hope this helps.
def status_params params.require(:status).permit(:name, :content, :user_id) end
Hugo Jenkins
1,860 PointsHugo Jenkins
1,860 PointsThanks John! I'll remember to do a more comprehensive search in future - perhaps including that in the 'ask a question' UI in addition to the 'questions like this' suggestions would have headed this question off at the pass!
Cheers Hugo
John Steer-Fowler
Courses Plus Student 11,734 PointsJohn Steer-Fowler
Courses Plus Student 11,734 PointsNo problem,
Let me know if you need any more help.
Keep up the good work