Rails, Sexier Than Ever.

3 days ago, Edge was patched to add a nicer syntax to our dear migrations.

Instead of doing:

create_table :people do |t|
  t.column :name, :string
  t.column :age,  :integer
end

You can now do:

create_table :people do |t|
  t.name :string
  t.age  :integer
end

While this is great, I found out that someone came up with an even nicer way of creating your migration, actually, a sexier way of doing migrations, and we all like sexy, don’t we? Otherwise we would not use Rails, would we?

Anyway thanks to this new plugin, your old Migration:

<code>class UpdateYourFamily < ActiveRecord::Migration
  create_table :updates do |t|
    t.column :user_id,  :integer
    t.column :group_id, :integer
    t.column :body,     :text
    t.column :type,     :string

    t.column :created_at, :datetime
    t.column :updated_at, :datetime
  end

  def self.down
    drop_table :updates
  end
end
</code>

can look sexier than ever:

class UpdateYourFamily < ActiveRecord::Migration
  create_table :updates do
    foreign_key :user
    foreign_key :group





<code>    text   :body
    string :type

    timestamps!
  end

  def self.down
    drop_table :updates
  end
end
</code>

Note that I didn’t test the code above and the self.up method seems to be missing, for more information, check the official post to give it a try:

./script/plugin install svn://errtheblog.com/svn/plugins/sexy_migrations
By Matt Aimonetti