Skip to content

Instantly share code, notes, and snippets.

@ivawzh
Forked from jocelynduc/active_record_macros.rb
Created April 5, 2020 07:40
Show Gist options
  • Save ivawzh/c156bfecd03277ef0dffa17ee4c0bad2 to your computer and use it in GitHub Desktop.
Save ivawzh/c156bfecd03277ef0dffa17ee4c0bad2 to your computer and use it in GitHub Desktop.
require 'active_record/connection_adapters/abstract/schema_definitions'
class ActiveRecord::ConnectionAdapters::TableDefinition
def publishing(*args)
options = args.extract_options!
column(:publish_up, :datetime, options)
column(:publish_down, :datetime, options)
end
end
@ivawzh
Copy link
Author

ivawzh commented Apr 5, 2020

extend activerecord migration macro/DSL.

usage:

class CreateUsers < ActiveRecord::Migration
  def self.up
    create_table :users do |t|
      t.string :first_name
      t.string :last_name
      t.timestamps
      t.publishing #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    end
  end

  def self.down
    drop_table :users
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment