Many times I want to always set the timestamps when a model is created. At times you will want to create a model in sql only for it to fail because you forgot to set the created_at
and updated_at
columns to some value. By setting a sane default you will avoid having to think about this in the future.
In your Rails application, copy the code below and paste it in the following file: lib/templates/active_record/migration/create_table_migration.rb.tt
class <%= migration_class_name %> < ActiveRecord::Migration[<%= ActiveRecord::Migration.current_version %>]
def change
create_table :<%= table_name %><%= primary_key_type %> do |t|
<% attributes.each do |attribute| -%>