Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby Active Record Associations in Rails Active Record Associations Has and Belongs to Many Associations

Brendan Whiting
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,678 Points

When did we create the User and Forum models?

I can't seem to find the part of the course where we created the User and Forum models. I see him accessing files that I don't have.

1 Answer

Wout Ceulemans
Wout Ceulemans
17,603 Points

I know this post is now more than a month old, but for the people who still have the same question: look at the teacher's notes for the instructions on how to create the 'community' project and the User and Forum models.


rails new community
cd community
rails g model User name:string nickname:string
rails g model Forum name:string public:boolean
bin/rails db:migrate

A simple way to put some data in is to add this to db/seeds.rb:

User.create(id: 1, name: 'Jay', nickname: 'dadjokes')
User.create(id: 2, name: 'Pasan', nickname: 'pasanpr')
User.create(id: 5, name: 'Alena', nickname: 'sketchings')
Forum.create(id: 1, name: 'Ruby', public: true)
Forum.create(id: 3, name: 'PHP', public: true)
Forum.create(id: 4, name: 'iOS', public: true)
Forum.create(id: 6, name: 'SQL', public: true)

and execute

bin/rails db:seed

bin/rails db:seed will basically execute the contents of db/seeds.rb in the correct context, just like executing them in the rails console.