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

Creating Relationships ? for Code Challenge: Model Associations

I've been stuck on this one for a while and have watched the video three times and still can't figure it out.

Question is: Add a belongs_to association to Status so that a status belongs to a user.

Here is what I did:

class Status < ActiveRecord::Base

attr_accessible :content, :user_id,

belongs_to :user

end

class User < ActiveRecord::Base

attr_accessible :content, :user_id,

belongs_to :status

end

2 Answers

Wouldn't it be on the User

has_many :statuses

Both shouldn't 'belong' to each other

Figured it out!

Thanks for your help!

This line doesn't belong:

attr_accessible :content, :user_id,

So it's just:

class Status < ActiveRecord::Base
belongs_to :user 
end

class User < ActiveRecord::Base
has_many :statuses
end