Add an --editor option to ActiveRecord migration generator #5829

Closed
wants to merge 1 commit into
from
@subelsky

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.

@timtyrrell

I can dig it +1

@mperham

🏩

@travisjeffery

Even better to configure your editor such that you can generate your migration without ever having to leave it!

@hoenth

+1

@oscardelben

+1

@travisjeffery that woud be an editor plugin.

@andrewle

+1 <3

@soffes

It would be cool if you specified --editor with no value if it just used the $EDITOR in your shell.

@subelsky

@samsoffes that is how it operates, see the description for that option

@soffes

Ah :lazy_default => ENV['EDITOR'] missed that. Nice!

@nfm

+1

@george

+1

@nerdEd

👍

@garygreyling

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!

@shime

❤️

@joshsz

Probably best if you continue to return path from the method, otherwise awesome and useful :) +1

@waugh

+1

@steveklabnik
Ruby on Rails member

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.

@subelsky

@steveklabnik I hear ya - is there a more general or useful way I should investigate? I'm not wedded to this implementation

@steveklabnik
Ruby on Rails member

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...

@jmoline

Anything that means I don't have to open my migrations folder (or worse, type in the file name datestamp) is a win.

+1

@jmoline

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.

@oscardelben

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.

@tilsammans

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?

@rafaelfranca
Ruby on Rails member

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.

For example:

To a controller generator we can open the controller file. Same with models, resources, etc.

@subelsky can you change it?

@tilsammans

Agreed, that would be useful.

@rafaelfranca
Ruby on Rails member

2 months without any answer, so I'm closing this one. Feel free to open a new request with the changes that I required.

@subelsky

@rafaelfranca sorry, I did not see your request from two months ago. I'll get on it this week.

@ndbroadbent

Hi, I've opened a new pull request at #8553, which opens all generated files, instead of just migrations.

@ndbroadbent

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment