Prev | Current Page 125 | Next

David Berube

"Practical Reporting with Ruby and Rails"

rb
create test/unit/booking_test.rb
create test/fixtures/booking.yml
exists db/migrate
create db/migrate/005_create_bookings.rb
Each of these commands creates a number of files. You now have files named after
the tables in the app/models directory, and those are the files you will edit. The generate
model command also creates unit tests and fixtures, as well as a migration for each table.
You can safely delete the migrations, since you already created all of the tables in your
initial migration. The unit test and fixture files are for unit testing; visit the Rails site
(http://rubyonrails.org) for information about their use.
First, edit the app/models/actor.rb file so it looks like Listing 5-4.
Listing 5-4. Actor Model (app/models/actor.rb)
class Actor < ActiveRecord::Base
has_many :bookings
end
Save the modified model file. Then edit app/models/booking.rb to look like Listing 5-5.
Listing 5-5. Booking Model (app/models/booking.rb)
class Booking < ActiveRecord::Base
belongs_to :actor
belongs_to :project
belongs_to :room
end
The actor and booking models contain all of the relationships you will use in this
example.


Pages:
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
Little River Band Londonbeat Alicja Majewska Christina Milian remonty silników elektrycznych