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 Active Record Associations in Rails Active Record Associations Association Methods

I am at a los here? Does anyone know what is wrong?

Where do i miss the point?

playground.rb
Pet = Pet.first
Owner = Pet.Owner.build
Pet.save

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,722 Points

You understood the .first method that's a good start!

You should use Owner model instead and then the .first method just like you did in your code. Then we can use the pets model inside the Owner and .create with an associative array name: "Your Pet Name"

Good luck with Rails it is one of the premier web frameworks to learn.

owner = Owner.first
owner.pets.create(name: "Snoopy")

Thanks for the great information.