2011-02-28 107 views
23

我在写一个教程,演示一些导轨命令。在我的机器railsscript/rails上工作得很好。是否有“首选”形式?这两个作品中哪一个更普遍?脚本/导轨与导轨

回答

38

当你运行一个Rails 3应用程序中的rails可执行文件,它会查找script/rails文件,如果它的存在,执行该文件中包含您传递给rails的参数。

您之所以使用rails而不是script/rails的原因通常是因为它更短。

还有一点需要注意,还有一个rails c命令,它在Rails 2应用程序中将在当前目录内生成一个名为c的应用程序文件夹。使用script/rails,这不会发生;相反,它会抱怨script/rails不存在。

14

在Rails 3中它应该只是rails。

0

在Rails 3应该是

rails 

...

+3

不,在老版本的Rails中没有'script/rails'。 – 2011-02-28 23:04:26

+0

感谢您的更正。 +1给你的答案@Ryan – Dty 2011-03-01 08:46:11

+0

对于导轨2,它是脚本/服务器。我还在我的.bashrc中为所有rails 2和3命令放置了一些别名。 – 2011-04-05 05:25:59

0

rails srails g scaffoldscript/rails,只是通过你的论点。rails一般者优先,因为它是更短,更快地打字。但是,如果有人试图在rails 2.X应用程序中使用rails srails c,它将添加该名称的另一个应用程序文件夹,因为2.X中的rails命令会生成一个应用程序。

如果您的演示旨在on Rails的3只运行使用rails ...如果它是更普遍务必注明2使用script/server ...rails ...

1

你应该写只是Rails的不是因为是首选,但轨道只是因为从这里开始,它将成为标准。 脚本/导轨用于以前版本的导轨,现在已弃用。

但是命令都在这一刻同样的效果,有什么是你不能使用Rails,而不是脚本做/导轨

0

script/rails命令是为Rails 2. Rails 3中使用railsscript/命令不适用于我的安装。

5

“轨道”将显示所有有关脚本用法:

Usage: rails COMMAND [ARGS] 

The most common rails commands are: 
generate Generate new code (short-cut alias: "g") 
console  Start the Rails console (short-cut alias: "c") 
server  Start the Rails server (short-cut alias: "s") 
dbconsole Start a console for the database specified in config/database.yml 
      (short-cut alias: "db") 
new   Create a new Rails application. "rails new my_app" creates a 
      new application called MyApp in "./my_app" 

In addition to those, there are: 
application Generate the Rails application code 
destroy  Undo code generated with "generate" 
benchmarker See how fast a piece of code runs 
profiler  Get profile information from a piece of code 
plugin  Install a plugin 
runner  Run a piece of code in the application environment 

All commands can be run with -h for more information. 
-5

Rails社区是赠送很多选项,使开发者的生活更轻松。命令栏做同样的事情,并被许多开发人员使用。由于同样的原因,导轨非常受欢迎。

+0

问题是询问是否有首选表单。 – riship89 2012-01-19 13:27:37

3

如果您使用的捆扎机,它实际上是更安全地说

bundle exec rails 

的,那么你可以放心的运转轨道的版本是在应用程序的捆绑。这同样可以为

bundle exec rake 
+1

如果有Gemfile文件,rails已经在捆绑的gem中运行。 – rewritten 2012-05-09 00:33:40

2

在窗口控制台可以说,我们必须编写Ruby脚本/服务器 但在Ubuntu脚本/服务器就够了

轨S和轨下rail3

1

script/rails是只能在项目应用程序文件夹中访问。特别是使用它会中断操作系统尝试从环境路径中找到rails,并可能引发错误(就像我在PC上那样)。要创建新的Rails应用程序,script/rails将不起作用,但rails会。我建议你坚持使用rails命令。

其他命令如script/generate,script/server,script/console都已成为rails调用的参数。