Prev | Current Page 337 | Next

David Berube

"Practical Reporting with Ruby and Rails"

Create Students Table Migration (db/migrate/001_create_students.rb)
class CreateStudents < ActiveRecord::Migration
def self.up
create_table :students do |t|
t.string :name, :limit=>45
t.string :employer, :limit=>45
t.timestamps
end
end
def self.down
drop_table :students
end
end
Note that the limit clause sets a maximum amount of characters in each column.
Listing 12-11 shows the code for your student model.
Listing 12-11. Student Model (app/models/student.rb)
class Student < ActiveRecord::Base
has_many :grades
end
Save this as app/models/student.rb.
You also need to generate a grade model, which represents the grade each student
received for each class:
ruby script/generate model grade
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/grade.rb
create test/unit/grade_test.rb
create test/fixtures/grades.yml
exists db/migrate
create db/migrate/002_create_grades.rb
CHAPTER 12 n CREATING REPORTS WITH RUBY AND MICROSOFT OFFICE 243
Next, add the code shown in Listing 12-12 to your second migration.


Pages:
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
Berghoff garnki Historia architekt wnętrz Warszawa zamek Kalendarze indywidualne http://www.jotan.pl