Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Suggestion: Change to create Rails 3.0 apps by `rails init app-name`

#4665

Suggestion

Please consider changing the Rails initialization command from "rails app-name" to "rails init app-name".

Rationale

Too often it happens that I try to run a Rails command like "rails s" accidentally under a non-Rails directory. That leads to unwished new directories named "s" or "console" etc.

It seems to me, creating new Rails apps doesn't happen too often to oppose adding these additional five (or two, shortcut "i") key presses to the command line syntax.

The changed syntax would be in line with e.g. Git commands.

Proposal for new command line messages

Under a non-Rails directory

  • "rails" — shows the help message just like now (just change the Usage & Example texts accordingly to "rails init ...")
  • "rails init" — creates a new Rails 3.0 application in current directory
  • "rails init ." — ditto
  • "rails init app-name" — creates a new Rails 3.0 application under ./app-name
  • "rails cmd" — returns printing something along the following to stdout:
    This is not a Ruby on Rails project. Did you mean to create one?
    Use 'rails init cmd' to create a Rails application named "cmd".
    Type 'rails' for help.
    

Under a Rails directory

  • "rails" — shows the help message just like now
  • "rails init [arg]" — prints something like:
    Can't initialize a new Rails application within the directory of another,
    please change to a non-Rails directory first.
    Type 'rails' for help.
    

Reported by Pyry Jahkola · May 22nd, 2010 @ 01:50 PM

State: open
Milestone: none
Assigned to: Mikel Lindsaar Mikel Lindsaar
Importance: none

Activity

  1. Harri Kauhanen
    Harri Kauhanen

    +1

    Excellent suggestion!

    There's fix #8994 to prevent creating projects with name 's', 'db' and so on with Rails 3, but that one is a bit ugly and does not really solve the problem. If you use both Rails 2.3 and Rails 3, you will keep creating those 's' projects for a long time (transition from Rails 2.3 to Rails 3 will certainly take some time). Anyone using rvm (Ruby version manager) knows what I am talking about. Rails 2.3.6 should also include a fix that would warn if you try to create project under name 'init'.

    'rails init' also feels much more natural than the current default behavior.

    May 22nd, 2010 @ 05:01 PM

  2. Harri Kauhanen
  3. Neeraj Singh
    Neeraj Singh

    +1 rails init <project_name> feels better.

    May 22nd, 2010 @ 06:37 PM

  4. vesan
    vesan

    +1

    This is change from how things have worked previously but IMHO change for the better.

    May 22nd, 2010 @ 08:19 PM

  5. Rohit Arondekar
    Rohit Arondekar

    +1 for the change, I've been hit by this same problem too and it would be nice to do rails init app-name. Can somebody start working on a patch?

    May 23rd, 2010 @ 11:10 AM

  6. Ryan Bigg
    Ryan Bigg
    • State changed from new to open

    +1, I've done this twice today!

    May 23rd, 2010 @ 11:26 AM

  7. Jeff Kreeftmeijer
    Jeff Kreeftmeijer

    +1

    Since the rails command handles everything (like generating scaffolds, starting the server and console etc.) in Rails 3, rails appname to generate an app doesn't feel right anymore. I think rails init appname is much more like the rest of the rails command and it'll keep me from having to remove directories like "s" or "console". Great suggestion! :)

    May 23rd, 2010 @ 12:01 PM

  8. Justin Baker
    Justin Baker

    +1

    This irritates me so much when I do it, everyone seems to do it too.

    May 24th, 2010 @ 03:45 AM

  9. Justin Baker
    Justin Baker

    I have a quick fix that I posted as a gist on github, obviously this probably needs more to see if you're already in a rails app directory, but if you're sick of the accidental app creation then it should work.

    May 24th, 2010 @ 03:54 AM

  10. Justin Baker
    Justin Baker

    And here's a patch, sorry there's so many comments

    May 24th, 2010 @ 05:29 AM

  11. Rohit Arondekar
    Rohit Arondekar
    • Assigned user set to Mikel Lindsaar

    May 26th, 2010 @ 01:11 PM

  12. Mikel Lindsaar
    Mikel Lindsaar
    • Milestone cleared.

    OK, thanks everyone, I took Juston's patch and have gone over it with DHH. We are going to make a couple of changes to your patch and then merge into rails/master.

    May 26th, 2010 @ 03:26 PM

  13. Rohit Arondekar
    Rohit Arondekar

    That's awesome news Mikel! Cheers Pyry for bringing it up and Justin for the patch. :)

    May 26th, 2010 @ 04:02 PM

  14. Justin Baker
    Justin Baker

    Documentation/Guides/Tutorials will have to be updated though, but the help message shouldn't be too hard for a user to follow if they run rails testapp after following a guide to create an application before this.

    May 26th, 2010 @ 05:46 PM

  15. Ryan Bigg
    Ryan Bigg

    Any further work on this?

    June 3rd, 2010 @ 10:56 AM

  16. Nicolas Blanco
  17. Mikel Lindsaar
  18. Justin Baker
    Justin Baker

    Awesome, been waiting to see it in rails/master!

    June 3rd, 2010 @ 01:17 PM

  19. Elise Huard
  20. Mikel Lindsaar
    Mikel Lindsaar

    You can kick tyres here with doc update here if you are interested.

    After some discussion it was changed from init to new, because it reads more like English and is a better word for what we are doing.

    Should be merged into master the next few.

    Mikel

    June 4th, 2010 @ 06:10 AM

  21. Ryan Bigg
    Ryan Bigg

    Thanks Mikel! Just installing now and will let you know if it goes or blows.

    June 4th, 2010 @ 06:53 AM

  22. Ryan Bigg
    Ryan Bigg

    The usage of the "rails" command still says

    rails APP_PATH [options]
    

    Maybe I'm being picky?

    June 4th, 2010 @ 07:07 AM

  23. Mikel Lindsaar
    Mikel Lindsaar

    Really? Where (or when)? I'll fix. I thought I found all of those...

    June 4th, 2010 @ 07:25 AM

  24. Mikel Lindsaar
    Mikel Lindsaar

    Thanks Ryan, good spotting, fixed in this commit

    June 4th, 2010 @ 07:37 AM

  25. Rohit Arondekar
    Rohit Arondekar

    Awesome work! Can't wait to see this in Rails master :)

    June 4th, 2010 @ 08:09 AM

  26. Ryan Bigg
  27. Uģis Ozols
    Uģis Ozols

    After this addition to rails is there a way to generate app with older rails version? In 3.0.0.beta3 I could use rails 2.3.8 app_name

    June 14th, 2010 @ 08:04 AM

  28. Ryan Bigg
    Ryan Bigg

    You can still do rails _2.3.8_ app_name to generate an app for 2.3.8.

    June 14th, 2010 @ 08:13 AM

  29. Uģis Ozols
    Uģis Ozols

    Oh I'm sorry... it's working perfectly. Messed up on my end :)

    June 14th, 2010 @ 08:55 AM

  30. Jeremy Kemper