-
Notifications
You must be signed in to change notification settings - Fork 0
Progress
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)
>> me = Person.new
=> #<Person id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> me.name =
?> “johnny”
=> “johnny”
>> me.name
=> “johnny”
>> me.save
=> true
>> u = Person.new
=> #<Person id: nil, name: nil, email: nil, created_at: nil, updated_at: nil>
>> u.name = “DeGrassi”
=> “DeGrassi”
>> me.save
=> true
>> u.save
=> true
#created two new Person objects and saved them to the people table
>> me.groups.create
=> #<Group id: 1, name: nil, created_at: “2010-05-27 07:23:13”, updated_at: “2010-05-27 07:23:13”>
>> me.groups.create
=> #<Group id: 2, name: nil, created_at: “2010-05-27 07:23:17”, updated_at: “2010-05-27 07:23:17”>
>> me.groups0.people
=> [#<Person id: 1, name: “johnny”, email: nil, created_at: “2010-05-27 07:22:23”, updated_at: “2010-05-27 07:22:23”>]
>> u.groups.create
=> #<Group id: 3, name: nil, created_at: “2010-05-27 07:23:45”, updated_at: “2010-05-27 07:23:45”>
>> u.groups
=> [#<Group id: 3, name: nil, created_at: “2010-05-27 07:23:45”, updated_at: “2010-05-27 07:23:45”>]
>> me.groups
=> [#<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”>]
>> u.groups0.people
=> [#<Person id: 2, name: “DeGrassi”, email: nil, created_at: “2010-05-27 07:23:04”, updated_at: “2010-05-27 07:23:04”>]
- 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
- people and groups. Here’s how to link two rows that are already created:
>> u = Person.all1
=> #<Person id: 2, name: “DeGrassi”, email: nil, created_at: “2010-05-27 07:23:04”, updated_at: “2010-05-27 07:23:04”>
>> grp = Group.all0
=> #<Group id: 1, name: “winners”, created_at: “2010-05-27 07:23:13”, updated_at: “2010-05-27 07:48:43”>
>> u.groups << grp
=> [#<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-
also I threw on some CSS that came with the tutorial.