I just started learning Ruby on Rails and loving it. I’ve run into several issues that seemed insurmountable, but with all the info out there I have been able to figure out my problem on my own… until now! I am on a Mac 10.7.5, ruby 2.0.0p195, rails 3.2.13
I am trying to create a new project but I get the following “error”:
Can’t initialize a new Rails application within the directory of another, please change to a non-Rails directory first.
Type ‘rails’ for help.
Some more background:
When everything was working OK, I wrote this: rails new profile
After that I noticed my “computer’s” name in the terminal window went from:
Tjtog-iMac:~ tejasmehta$
TO
Tjtog-iMac:profile tejasmehta$
I searched online for hours and can’t find a way to solve this on my end.
Your computer name did not change. Your computer name is Tjtog-iMac. The part after the “:” is the directory you are in. At first you were in “~” which is your home directory. Then you were in “profile” which is the directory of the rails app you created.
Can you confirm what directory you are in when you try to create a new app and get the error? What is the output of the “pwd” command? What is the output of the “ls” command?
Here's what I think happened. You created your first Ruby application
called "profile".. it generated successfully and terminal opened up the
directory. Now you want to create another rails app, but terminal is
still in that rails directory of "profile" (hence the name profile next
to your imac's name).
To get out of it, type "cd ~/Desktop" (which stands for "change
directory" and that will change the directory to your desktop. Then type
"rails new {name}" for your next app, and it should work again!
If you find yourself having trouble with this, I recommend going through
the first chapters of the Rails Tutorial book by Michael Hartl. If I
remember correctly, he discusses the command prompts and other stuff
around ruby and rails at great lengths.
Let me know if this worked out for you, otherwise we'll have to find
another solution!
Your issue isn't really with rails, it's in understanding the *nix
directory structure and how to use the command line, I think.
If you open your Finder, and go to your home directory, you will
probably see a folder there called "profile". When you are in the
Terminal, the prompt:
Tjtog-iMac:~ tejasmehta$
refers to:
your machine name: Tjtog-iMac
~: shorthand for your home directory
tejasmehta: your user name I'm assuming
when you created the rails app profile, it created a folder 'profile'
under your home directory.
to make a new app, go back to your home directory (or another directory
other than 'profile') and run the rails new app again.
I would strongly suggest getting the Mac Missing Manual for your edition
of OS/X and read through it.