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

Brendan Whiting
MOD
Brendan Whiting
Front End Web Development Treehouse Moderator 84,109 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,601 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.

TL;DR

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.