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
c song
4,296 PointsCreating relationships between users and statuses, NoMethodError in Statuses#show, undefined method `user'
Help! Working through the 'Creating relationships between users and statuses' lesson, I keep encountering a NoMethodError in Statuses#show, undefined method `user' whenever I run <%= @status.user.first_name %>.
I'm using Ruby 4.0. I've noticed many others have encountered similar problems but I haven't been able to find anything on here that successfully resolves it. All of my databases are up to date and have been migrated.
Interestingly, I can run
<%= @status.user_id %> and everything works fine. Any ideas on what's going on here? Many thanks!
5 Answers
Brandon Barrette
20,485 PointsDo you have the proper associations in the model? Since status.user_id is working, but status.user is not, this sounds to be the case.
In status.rb you should have:
belongs_to :user
In user.rb you should have:
has_many :users
c song
4,296 PointsHi Brandon, thanks for the response. Unfortunately, the troubles seem to go much deeper than that. I've followed all the video instructions to a T. The only potential issue I'm thinking it could be is that attr_accessible doesn't work on Rails 4, so I'm unable to run the:
attr_accessible :content, user_id
in my status.rb file. Anyone know a way around this issue? Thanks!
Danny Freed
254 PointsI have the same problem....anyone figure this out?
Tate Hanawalt
16,895 PointsYea I have been stuck on this for like 2 hours
Tate Hanawalt
16,895 Pointshttps://teamtreehouse.com/forum/no-method-error-in-statusesshow
I was using ruby 2. something and rails 4. and there is a devise security issue that needs to be taken care of described in the link above