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 trialkekl
14,598 PointsRelationships code challenge 2: Problem
Hello,
i have a problem with the related code challenge.
The challenge Task is:
Let's say we have a BlogPost model and a Comment model
that represents comments someone might leave on a blog
post. The comments table includes a blog_post_id column.
Please setup the relationships correctly.
Here is my code:
class BlogPost < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :blogpost
end
I think my code is correct but the error message says:
Bummer! Remember, `belongs_to` always wants the
singular version of the relationship.
Thanks
1 Answer
Maciej Czuchnowski
36,441 PointsYou need an underscore:
belongs_to :blog_post
Maciej Czuchnowski
36,441 PointsWhen the model has name like this: BlogPost
you can assume that there will be an underscore before post
. Also, the name of the column was blog_post_id
, so it HAS TO take blog_post
.
kekl
14,598 PointsIt works! :) Thank you so much
Paul Stettnisch
10,712 PointsPaul Stettnisch
10,712 PointsTricky this one....got me too.