the first thing Rails devs do after running a migration is usually open that file in an editor. I added an --editor option here that does this for you automatically. I didn't see an easy way to test this (do the generators have their own tests?) but if there's a place where that should go, I'll gladly add them to this patch.
Add an --editor option to migration generator; opens the migration in…
… an editor after creation
I can dig it +1
Even better to configure your editor such that you can generate your migration without ever having to leave it!
@travisjeffery that woud be an editor plugin.
It would be cool if you specified --editor with no value if it just used the $EDITOR in your shell.
@samsoffes that is how it operates, see the description for that option
Ah :lazy_default => ENV['EDITOR'] missed that. Nice!
:lazy_default => ENV['EDITOR']
Its like sitting in a room at dusk while it gets progressively darker, only for someone to walk in, flip a switch and have you realise whats been missing the past 2 hours! + 1 fo sho!
Probably best if you continue to return path from the method, otherwise awesome and useful :) +1
Oh man, I'm not sure how I feel about the particular solution to this problem, but I feel this pain every time I run rails g.
@steveklabnik I hear ya - is there a more general or useful way I should investigate? I'm not wedded to this implementation
I'll give it some thought, but I'm not sure, to be honest.
It's that it's different than every other generator that bugs me, the lack of symmetry. Then again, none of them do this...
Anything that means I don't have to open my migrations folder (or worse, type in the file name datestamp) is a win.
That being said, I do understand @steveklabnik's objection. Maybe this doesn't belong in rails core, but would work better as a Guard gem that automatically opens any newly created file in the migrations folder?
I'm not just suggesting it so I can install and begin using it right away, either. Honest.
I'm not sure about the lazy default though, it's not rare that I generate a migration and I run it right away.
Edit: maybe that's what it does already, I'm just not sure what lazy_default does.
I want this every time I generate a migration.
What are the objections for not merging it, exactly? @steveklabnik I completely agree with you about the mess that is the various rails and rake commands. However, that does not invalidate this simple patch.
@tenderlove any chance this gets pulled in?
I think that this can be pulled in but I want to propose get this is a higher level. We can define this option in every generator and open the lead file from it.
To a controller generator we can open the controller file. Same with models, resources, etc.
@subelsky can you change it?
Agreed, that would be useful.
2 months without any answer, so I'm closing this one. Feel free to open a new request with the changes that I required.
@rafaelfranca sorry, I did not see your request from two months ago. I'll get on it this week.
Hi, I've opened a new pull request at #8553, which opens all generated files, instead of just migrations.
Hi all, if you want to use the --editor option in your Rails 3 app, you can run this command from your app directory:
curl https://gist.github.com/raw/4342095/rails -o script/rails
(Since Rails 3 isn't accepting new features.)
See my blog post if you want to use it globally for all Rails 3 apps.