Search code examples
ruby-on-railspluginsmigrationhookrails-generate

Adding a hook to script/generate migration


I do my Rails dev from xterm and in vim.

I'm getting sick of running script/generate migration do_whatever, then trawling through db/migrate trying to tab-complete to 20091015235018_do_whatever when there's 5 other migrations with similar timestamps.

What's the best way to add a hook to open the generated migration in vim?

I'd rather not hack into Rails' core in /usr/lib as I work from several systems and can see myself wanting to create numerous such hooks. However, it doesn't really seem plugin worthy.

There are lots of simple ways to get the name of the generated file, but I'm not sure how to cleanly hook it into the generation. What do you think?


Solution

  • A better option with vim is to use rails.vim and type :Rmigration do<TAB> It ignores the timestamp ...

    You can also create and edit a migration in one go by typing :Rgenerate migration ...