O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test Your Knowledge

Quiz

  1. How do you run migrations forward?

  2. How do you create a new migration?

  3. What should the self.down method do in a migration?

  4. What Rails data type should you use to represent currency values?

  5. How do you add a new field to a record?

Answers

  1. With the rake db:migrate command.

  2. To keep in line with Rails’ timestamp-based naming convention, it’s best to use script/generate migration NameOfMigration, and then edit the resulting file in the db/migrate directory.

  3. The self.down method defines what should happen if the migration is rolled back using rake db:rollback. The tables, column, and indexes created in self.up need a corresponding removal process in self.down.

  4. The :decimal type is the most precise way to keep track of money. It can keep track of cents to the right of the decimal point and will contain values with a fixed number of decimal places much more accurately than :float.

  5. New fields get created with add_column, as “fields” are represented as columns and the records that contain them as rows.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required