Listing 12-14. Create Training Classes Table Migration
(db/migrate/003_create_training_class.rb)
class CreateTrainingClasses < ActiveRecord::Migration
def self.up
create_table :training_classes do |t|
t.string :name, :limit=>45
end
end
def self.down
drop_table :training_classes
end
end
Listing 12-15 shows the code for the training_class model.
Listing 12-15. Training Class Model (app/models/training_class.rb)
class TrainingClass < ActiveRecord::Base
has_many :grades
end
Save this as app/models/training_class.rb.
Now you need to create a database named training_development, and then edit your
config/database.yml file with the MySQL connection settings for your machine.
Then you can run the three migrations:
rake db:migrate
(in /path/to/your/project)
== CreateStudents: migrating ==================================================
-- create_table(:students)
-> 0.0310s
== CreateStudents: migrated (0.0310s) =========================================
CHAPTER 12 n CREATING REPORTS WITH RUBY AND MICROSOFT OFFICE 245
== CreateGrades: migrating ====================================================
-- create_table(:grades)
-> 0.
Pages:
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351