Quantcast
Channel: Good notes posted by hosiawak
Viewing all articles
Browse latest Browse all 8

Useful in migrations (ActiveRecord::Base#reset_column_information)

$
0
0

The most common usage pattern for this method is probably in a migration, when just after creating a table you want to populate it with some default values, eg:

class CreateJobLevels<ActiveRecord::Migrationdef self.upcreate_table:job_levelsdo|t|t.integer:idt.string:namet.timestampsendJobLevel.reset_column_information%w{assistant executive manager director}.eachdo|type|JobLevel.create(:name=>type)endenddef self.downdrop_table:job_levelsendend

Viewing all articles
Browse latest Browse all 8

Trending Articles