在 ruby​​ 脚本中更改目录? [英] To change directory inside a ruby script?

查看:39
本文介绍了在 ruby​​ 脚本中更改目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个新的 rails 应用程序并为该应用程序启动 rails 服务器,一切都来自 ruby​​ 脚本.

I want to create a new rails application and fire up the rails server for that application, everything from a ruby script.

我的代码如下:

#!/usr/bin/env ruby
system "rails new my_app"
system "cd my_app"
system "rails server &"

但是,在运行rails server &"时路径不在 my_app 文件夹中,而是在父文件夹中.

However, when running "rails server &" the path is not in the my_app folder, but in the parent folder.

有没有办法更改脚本内的目录,以便我可以为该新应用程序运行rails server"、rake about"和rake db:migrate"?

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.

推荐答案

使用 Dir.chdir:

Dir.chdir "my_app"

这篇关于在 ruby​​ 脚本中更改目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆