Skip to content
theJohnnyBrown edited this page Sep 14, 2010 · 12 revisions

3/27:

created models, views, controllers for people and groups. controller/view is very basic, for example the people view generates a page with each person’s name and below the name shows all the groups associated with this person.

Used rake db:migrate to create the tables

To see it working I used the ruby console to add a few basic rows to each table. Here’s how to do it so rails automatically handles the join table:
johnny@johnny-laptop:~/Documents/rails/acm_site$ script/console Loading development environment (Rails 2.3.5) <br> >> me = Person.new <br> => #<Person id: nil, name: nil, email: nil, created_at: nil, updated_at: nil> <br> >> me.name = "johnny" <br> => "johnny" <br> >> me.save <br> => true <br> >> u = Person.new <br> => #<Person id: nil, name: nil, email: nil, created_at: nil, updated_at: nil> <br> >> u.name = "DeGrassi" <br> => "DeGrassi" <br> >> me.save <br> => true <br> >> u.save <br> => true<br> <br> #created two new Person objects and saved them to the people table <code> >> me.groups.create<br> => #<Group id: 1, name: nil, created_at: “2010-05-27 07:23:13”, updated_at: “2010-05-27 07:23:13”><br> >> me.groups.create<br> => #<Group id: 2, name: nil, created_at: “2010-05-27 07:23:17”, updated_at: “2010-05-27 07:23:17”><br> >> me.groups0.people<br> => [#<Person id: 1, name: “johnny”, email: nil, created_at: “2010-05-27 07:22:23”, updated_at: “2010-05-27 07:22:23”>]<br> >> u.groups.create<br> => #<Group id: 3, name: nil, created_at: “2010-05-27 07:23:45”, updated_at: “2010-05-27 07:23:45”><br> >> u.groups<br> => [#<Group id: 3, name: nil, created_at: “2010-05-27 07:23:45”, updated_at: “2010-05-27 07:23:45”>]<br> >> me.groups<br> => [#<Group id: 1, name: nil, created_at: “2010-05-27 07:23:13”, updated_at: “2010-05-27 07:23:13”>, #<Group id: 2, name: nil, created_at: “2010-05-27 07:23:17”, updated_at: “2010-05-27 07:23:17”>]<br> >> u.groups0.people<br> => [#<Person id: 2, name: “DeGrassi”, email: nil, created_at: “2010-05-27 07:23:04”, updated_at: “2010-05-27 07:23:04”>]<br>

  1. 1. used each Person to create new groups, which are now linked to that person, as (Person).groups shows. Now make sure to save all the
    2. people and groups. Here’s how to link two rows that are already created:
    >> u = Person.all[1]<br> => #<Person id: 2, name: “DeGrassi”, email: nil, created_at: “2010-05-27 07:23:04”, updated_at: “2010-05-27 07:23:04”><br> >> grp = Group.all[0] => #<Group id: 1, name: “winners”, created_at: “2010-05-27 07:23:13”, updated_at: “2010-05-27 07:48:43”><br> >> u.groups << grp<br> => [#<Group id: 3, name: “catz”, created_at: “2010-05-27 07:23:45”, updated_at: “2010-05-27 07:58:31”>, #<Group id: 1, name: “winners”, created_at: "2010-05-<br> # also I threw on some CSS that came with the tutorial.

Clone this wiki locally