为什么Ruby“脚本/生成”返回“没有这样的文件或目录”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4320759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:45:33  来源:igfitidea点击:

Why does Ruby "script/generate" return "No such file or directory"?

ruby-on-railsrubyscriptgenerate

提问by jyoseph

I am having trouble using script/generate. I am following the tree based navigationtutorial, which says to use script/plugin install git://github.com/rails/acts_as_tree.gitor script/generate nifty_layout.

我在使用script/generate. 我正在关注基于树的导航教程,其中说要使用script/plugin install git://github.com/rails/acts_as_tree.gitscript/generate nifty_layout

I keep getting:

我不断得到:

No such file or directory -- script/plugin

没有这样的文件或目录——脚本/插件

I've tried these variations:

我试过这些变化:

script/generate nifty_layout
rails generate nifty_layout
ruby script/generate nifty_layout
ruby generate nifty_layout

and they all tell me:

他们都告诉我:

-bash: script/generate: No such file or directory

-bash: 脚本/生成: 没有那个文件或目录

Am I missing something? Total ruby nuby here and I just can't seem to find an answer.

我错过了什么吗?全部 ruby​​ nuby 在这里,我似乎无法找到答案。

edit: rails 3 on Mac OS X 10.6

编辑:Mac OS X 10.6 上的 rails 3

回答by Nick

Rails 3 is your problem (or rather the cause of). Since rails 3 all of the "script/whatever" commands have been replaced with "rails whatever".

Rails 3 是您的问题(或者更确切地说是问题的原因)。从 rails 3 开始,所有的“script/whatever”命令都被替换为“railswhatever”。

So now you want "rails generate ..." or "rails server" instead.

所以现在你想要“rails generate ...”或“rails server”。

Be sure to watch version numbers or post dates when looking at tutorials :) linkage: Missing script/generate in Rails 3

查看教程时,请务必查看版本号或发布日期:) 链接: Rails 3 中缺少脚本/生成

回答by the Tin Man

There is a LOT of out-of-date information on the interwebs for Rails now as a result of it evolving quickly and being so popular. I use the Ruby on Rails Guidesas my first stop for information as those pages seem to be the most current.

由于 Rails 发展迅速并且非常流行,现在在 Internet 上有很多关于 Rails 的过时信息。我使用Ruby on Rails 指南作为我获取信息的第一站,因为这些页面似乎是最新的。

The rails generateinfo seems current.

rails generate信息似乎电流。

回答by Jed Schneider

you may try a couple things, first, make sure since you are using rails 3 that you have run 'bundle install'. depending on how you installed rails and which version of bundler you are using, it may not be finding your rails binary to execute the rails generate ..so you may try prefixing it with bundle exec rails gbut that is deprecated and you should get a warning if you call it. Also, make sure you are following ryan's instructions for rails 3 (and run bundle install once you add to the gemfile) on his library: https://github.com/ryanb/nifty-generators

你可以尝试一些事情,首先,确保因为你使用的是 Rails 3,你已经运行了“捆绑安装”。根据您安装 rails 的方式以及您使用的 bundler 版本,它可能找不到您的 rails 二进制文件来执行,rails generate ..因此您可以尝试为其添加前缀,bundle exec rails g但不推荐使用它,如果您调用它,您应该收到警告。另外,请确保您在他的库中遵循 ryan 对 rails 3 的说明(并在添加到 gemfile 后运行 bundle install):https: //github.com/ryanb/nifty-generators

回答by sscirrus

As a shortcut to rails server, you can use 'rails s'. Similarly for the console, 'rails c'.

作为 Rails 服务器的快捷方式,您可以使用“rails s”。同样对于控制台,'rails c'。