samhuri.net/public/posts/2006/02/some-textmate-snippets-for-rails-migrations.html.md

1.9 KiB

My arsenal of snippets and macros in TextMate is building as I read through the rails canon, Agile Web Development... I'm only 150 pages in so I haven't had to add much so far because I started with the bundle found on the rails wiki. The main ones so far are for migrations.

Initially I wrote a snippet for adding a table and one for dropping a table, but I don't want to write it twice every time! If I'm adding a table in up then I probably want to drop it in down.

What I did was create one snippet that writes both lines, then it's just a matter of cut & paste to get it in down. The drop_table line should be inserted in the correct method, but that doesn't seem possible. I hope I'm wrong!

Scope should be source.ruby.rails and the triggers I use are above the snippets.

mcdt: Migration Create and Drop Table

create_table "${1:table}" do |t|
    $0
end
${2:drop_table "$1"}

mcc: Migration Create Column

t.column "${1:title}", :${2:string}

marc: Migration Add and Remove Column

add_column "${1:table}", "${2:column}", :${3:string}
${4:remove_column "$1", "$2"}

I realize this might not be for everyone, so here are my original 4 snippets that do the work of marc and mcdt.

mct: Migration Create Table

create_table "${1:table}" do |t|
    $0
end

mdt: Migration Drop Table

drop_table "${1:table}"

mac: Migration Add Column

add_column "${1:table}", "${2:column}", :${3:string}

mrc: Migration Rremove Column

remove_column "${1:table}", "${2:column}"

I'll be adding more snippets and macros. There should be a central place where the rails bundle can be improved and extended. Maybe there is...