I want to create a new rails application and fire up the rails server for that application, everything from a ruby script.
My code look like this:
#!/usr/bin/env ruby system "rails new my_app" system "cd my_app" system "rails server &"
However, when running "rails server &" the path is not in the my_app folder, but in the parent folder.
Is there a way to change directory inside a script so that i can run "rails server", "rake about" and "rake db:migrate" for that new application?
All work around tips would be appreciated.
Using Ruby's Mkdir Method To Create A New Directory If you want to create a new folder with Ruby you can use the Dir. mkdir method. If given a relative path, this directory is created under the current path ( Dir. pwd ).
cd means change directory.
Don't listen to them, Dir.chdir("dir")
will probably do the wrong thing. What you almost always want is to limit change to a particular context, without affecting the rest of the program like this:
#!/usr/bin/env ruby system "rails new my_app" Dir.chdir("my_app") do system "rails server &" end # back where we were, even with exception or whatever
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With