运行”捆绑安装”命令失败
所有,
我在特定目录中创建一些文件后使用以下命令。它给我一条错误消息。
命令
desc "new project_name", "new a project with a name"
def new(project_name = 'my_project')
directory 'doc', project_name
path = Dir.pwd + '/' + project_name
system("cd #{path}")
run('bundle install')
#But this command is working that makes me so confusing
#run("cd #{path} && bundle install")
#puts "Initializing complete"
end
错误
create aaaaaaa/views/index.slim
create aaaaaaa/views/layout.slim
run bundle install from "."
Could not locate Gemfile
我看到rails在初始化新项目时直接运行此命令bundle install
,rails如何做到这一点?我如何使这个命令起作用。
all,
I use the below command after creating some files in a specific directory. It gets me a error message.
The command
desc "new project_name", "new a project with a name"
def new(project_name = 'my_project')
directory 'doc', project_name
path = Dir.pwd + '/' + project_name
system("cd #{path}")
run('bundle install')
#But this command is working that makes me so confusing
#run("cd #{path} && bundle install")
#puts "Initializing complete"
end
The error
create aaaaaaa/views/index.slim
create aaaaaaa/views/layout.slim
run bundle install from "."
Could not locate Gemfile
I see the rails that runs this commend bundle install
directly when it initializes a new project, how the rails can do that? how do i make this command working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
系统
创建子进程然后退出。子进程更改了目录然后完成,但您的脚本仍然认为它位于进程认为它所在的任何工作目录中。如果您想更改运行脚本的进程的工作目录,请使用
Dir.chdir()
。system
creates a subprocess and then exits. The subprocess changed directory and then finished, but your script still thinks it's in whatever working directory the process thinks it's in.If you want to change the working directory of the process running the script, use
Dir.chdir()
.Rails 实际上使用了一个小技巧,将捆绑安装命令“打印”到 shell 并运行它。请注意输出中的反引号。
我还认为系统命令不一定会改变进程的当前工作目录(就 Thor 的运行命令而言)。
Rails actually uses a little hack that "prints" the bundle install command to the shell and runs it. Notice the back ticks in the output.
I also think that the system command doesn't necessarily alter the processes' current working directory (in terms of Thor's run command).