Skip to content

Instantly share code, notes, and snippets.

@nateware
Created September 26, 2011 19:23

Revisions

  1. Nate Wiger created this gist Sep 26, 2011.
    22 changes: 22 additions & 0 deletions mini_record_syntax.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    class Contact < ActiveRecord::Base
    col :name, :type => String, :null => false
    col :contact_type_id, :type => Integer, :null => false
    col :address, :type => String, :limit => 1000
    col :city, :type => String
    col :state, :type => String, :limit => 40
    col :zip, :type => String, :limit => 20
    col :phone, :type => String, :limit => 20
    col :email, :type => String, :limit => 100
    end

    # in Ruby 1.9 it looks even cleaner:
    class Contact < ActiveRecord::Base
    col :name, type: String, null: false
    col :contact_type_id, type: Integer, null: false
    col :address, type: String, limit: 1000
    col :city, type: String
    col :state, type: String, limit: 40
    col :zip, type: String, limit: 20
    col :phone, type: String, limit: 20
    col :email, type: String, limit: 100
    end