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 trialAdam Zuckerberg
22,248 PointsIs there an error in this that you need "blog_post" to pass even though the class name is "BlogPost" w/ no underscore?
? - shouldn't the correct answer be belongs_to :blogpost (singular, no underscore)?
class BlogPost < ActiveRecord::Base
has_many :comments
end
class Comment < ActiveRecord::Base
belongs_to :blog_post
end
1 Answer
Maciej Czuchnowski
36,441 PointsCamel case, with capital P in the middle in the name of the model, translates into an underscore in all other places.
Maciej Czuchnowski
36,441 PointsMaciej Czuchnowski
36,441 PointsBlogpost would translate into :blogpost.
Conrad Spotts
11,768 PointsConrad Spotts
11,768 PointsHahaha, This made me question everything I learned in the video for a good 10 minutes. The help text just kept telling me to remember that "belongs_to" belongs to the singluar, but that's what I had set up.
I don't recall it being stated anywhere in the video that camel case equates to an underscore in other places. It was demonstrated with TimeEntries, when I think about, but it wasn't clear to me that the difference was actual syntax and not just the instructor deciding to name something.
Thank you for the info!