Ruby-on-rails 输入“rails 控制台”没有启动?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3744567/
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
typing 'rails console' doesn't start?
提问by Blankman
I typed this:
我输入了这个:
>rails console
and got this:
得到了这个:
Usage:
rails new APP_PATH [options]
Options:
[--skip-gemfile] # Don't create a Gemfile
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)
# Default: sqlite3
..
..
.
I'm following along the rails tutorial and got stuck on this.
我正在遵循 rails 教程并被困在这个问题上。
I have rails 3.0 installed.
我安装了 rails 3.0。
回答by Yannis
Are you in the root path of your app when you type $ rails console?
键入时是否在应用程序的根路径中$ rails console?
Tip: $ rails cis a shortcut for $ rails console
提示:$ rails c是一个快捷方式$ rails console
回答by Guillaume Roderick
In case anyone else hits this, my symptoms were:
如果其他人遇到此问题,我的症状是:
I'd deployed my application with Capistrano 3
我用 Capistrano 3 部署了我的应用程序
I cd'd into my application directory, and rails console didn't work
我进入了我的应用程序目录,而 rails 控制台没有工作
Turned out I'd included the bin folder as a symlinked directory in my cap deploy, as follows:
结果我将 bin 文件夹作为符号链接目录包含在我的 cap 部署中,如下所示:
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system}
... and my bin directory in 'shared' was empty.
...我在“共享”中的 bin 目录是空的。
Two fixes:
两个修复:
- Ensure your linked bin directory has the correct contents (have a look inside your #{RAILS_ROOT}/bin directory for what this is, OR
- Don't symlink bin
- 确保链接的 bin 目录具有正确的内容(查看 #{RAILS_ROOT}/bin 目录中的内容,或
- 不要符号链接 bin
I then re-deployed and it works.
然后我重新部署,它的工作原理。
回答by Nick
I just ran into this same problem while upgrading a Rails 2 app to Rails 3. When running rails console(or really rails [anything]) in my app's root directory, I would see general rails newusage output (as Blankman referenced in the original question).
我在将 Rails 2 应用程序升级到 Rails 3 时遇到了同样的问题。在我的应用程序的根目录中运行rails console(或真的rails [anything])时,我会看到一般rails new用法输出(如原始问题中引用的 Blankman)。
The problem was that I had not removed the old Rails 2 scripts from the scriptdirectory. After removing everything in the scriptdirectory and adding the script/railsfile that is auto-generated in each new Rails 3 app, the railscommand now works as expected.
问题是我没有从script目录中删除旧的 Rails 2 脚本。删除script目录中的所有内容并添加script/rails在每个新 Rails 3 应用程序中自动生成的文件后,该rails命令现在可以按预期工作。
In order to get the latest contents of the script/railsfile, generate a new app and copy the file into your Rails 2 app that you're upgrading. As of Rails 3.0.7, here's what's in this file:
为了获取script/rails文件的最新内容,请生成一个新应用程序并将该文件复制到您要升级的 Rails 2 应用程序中。从 Rails 3.0.7 开始,这是这个文件中的内容:
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
回答by Goro
I had this problem when I upgraded Rails 2 to 3 and was able to fix it by doing what Nick said, then also running bundle exec rails console production.
我在将 Rails 2 升级到 3 时遇到了这个问题,并且能够通过按照尼克所说的进行修复,然后运行bundle exec rails console production.
回答by Richard Cook
In Rails 2.3.x the command is script/consolewithin a given Rails application directory to start a Ruby console with the default Rails environment loaded into memory. Not sure if Rails 3.0 is the same or not.
在 Rails 2.3.x 中,该命令script/console位于给定的 Rails 应用程序目录中,用于启动 Ruby 控制台,并将默认 Rails 环境加载到内存中。不确定 Rails 3.0 是否相同。
回答by kenny
You need to into the project directory and command rails consoleeg:
您需要进入项目目录和命令,rails console例如:
D:\workspace\>rails blog
D:\workspace\>cd blog
D:\workspace\blog\> rails c
loading en...
回答by Andrew Kuklewicz
are you in a rails 3 app directory?
你在 rails 3 应用程序目录中吗?
do you have multiple versions of rails installed?
您是否安装了多个版本的导轨?
try checking 'which rails', and make sure this is a rails 3 executable you are running - that usage looks like rails 2.x.
尝试检查“which rails”,并确保这是您正在运行的 rails 3 可执行文件 - 用法看起来像 rails 2.x。
回答by eli
You are running the correct command (rails console), but you are most likely not in the working directory for this application. Change directory to the root of your rails application (beneath which you will find /scripts, /app, etc.), and the command should work as desired.
您正在运行正确的命令 ( rails console),但您很可能不在此应用程序的工作目录中。目录更改为您的Rails应用程序的根目录(这下你会发现/scripts,/app等),并根据需要在命令应该工作。
Note: Using script/consoleor ruby script/consoleis for earlier versions of Rails.
注意:使用script/console或ruby script/console用于较早版本的 Rails。
回答by Arthur
In my case bin/rails cworked off my app root folder
在我的情况下bin/rails c,我的应用程序根文件夹

