2012-04-07 75 views
9

我是ruby和rails的新手,并且我在rails中安装了rails。但是当我通过键入“rails s”去启动服务器时,它不会启动并且出现以下消息。 但我可以通过命令栏new new_project创建一个新项目。请轨道专家帮助我。Rails服务器没有通过命令“Rails s”启动

[email protected]:~# rails s Usage: rails new APP_PATH [options] Options: -j, [--javascript=JAVASCRIPT] 
# Preconfigure for selected JavaScript library # Default: jquery -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL) [--dev] 
# Setup the application with Gemfile pointing to your Rails checkout -J, [--skip-javascript] # Skip JavaScript files [--edge] 
# Setup the application with Gemfile pointing to Rails repository -G, [--skip-git] 
# Skip Git ignores and keeps -d, [--database=DATABASE] 
# Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) 
# Default: sqlite3 -b, [--builder=BUILDER] 
# Path to a application builder (can be a filesystem path or URL) -r, [--ruby=PATH] 
# Path to the Ruby binary of your choice 
# Default: /usr/bin/ruby1.8 [--old-style-hash] 
# Force using old style hash (:foo => 'bar') on Ruby >= 1.9 [--skip-gemfile] 
# Don't create a Gemfile -O, [--skip-active-record] 
# Skip Active Record files [--skip-bundle] # Don't run bundle install -T, [--skip-test-unit] 
# Skip Test::Unit files -S, [--skip-sprockets] 
# Skip Sprockets files Runtime options: -q, [--quiet] 
# Supress status output -f, [--force] 
# Overwrite files that already exist -s, [--skip] 
# Skip files that already exist -p, [--pretend] 
# Run but do not make any changes Rails options: -h, [--help] 
# Show this help message and quit -v, [--version] 
# Show Rails version number and quit Description: The 'rails new' command creates a new Rails application with a default directory structure and configuration at the path you specify. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. Example: rails new ~/Code/Ruby/weblog This generates a skeletal Rails installation in ~/Code/Ruby/weblog. See the README in the newly created application to get going 
+0

您安装了哪个版本的导轨?你有没有创建一个新的rails应用程序? – alex 2012-04-07 12:18:46

+0

yes alredy通过命令“rails new new_project”创建应用程序..它被创建:( – 2012-04-07 20:04:32

回答

9
  1. 您需要创建一个新的Rails应用程序(除非你已经有一个)

    rails new my_app 
    
  2. 转到您的应用程序目录

    cd my_app 
    
  3. 开始在该目录服务器

    rails s 
    
+2

警告:这在轨道3格式。随着轨道2这将创建在当前目录中的一个全新的Rails应用程序!佑! – 2012-04-07 18:40:08

+0

@ fl00r另一个错误再次出现 请您可以点击此链接 http://stackoverflow.com/questions/10057961/rails-server-does-not-start – 2012-04-07 20:15:52

+0

将'gem“therubyracer”'添加到您的'Gemfile'中 – fl00r 2012-04-07 21:34:30

5

一旦你创建的项目,cd倒是进去:

使用script/server,如果你是在轨道上2.x版

使用script/rails server,如果你是在轨道上3.x版

使用bin/rails server,如果你是在轨道上4.x版

+0

“rails s”是版本3.x的一个很好的快捷方式 - 问题是他没有cd到目录中 – Sprachprofi 2012-04-07 14:53:37

+0

虽然与Rails 2它将创建一个全新的轨道应用程序,无论他在哪个目录! – 2012-04-07 18:38:53

+0

你可以按照此链接请http://stackoverflow.com/questions/10057961/rails-server-does-not-start – 2012-04-07 20:25:58

1

在启动rails服务器之前,y你必须cd进入你的应用程序的目录。这是因为服务器需要知道它应该提供哪个应用程序。

28

更好的方法是使用更新你的bin下面的命令

bundle exec rake rails:update:bin 
+0

谢谢,这确实有帮助。在旧版Rails应用程序中找不到不工作的rails命令和工作的命令之间的区别。你能解释一下吗?为什么这个目录缺失? – 2014-05-26 14:00:32

+0

非常感谢您的先生! – 2014-09-16 19:04:53

+0

是的,我也困惑,为什么'轨new'命令摆在首位并没有简单地创建该命令创建的文件。 'rails new'确实创建了'bin \ bundle'和'bin \ setup',但不是'bin \ rails'和'bin \ rake'。 – 2015-08-27 00:00:13

0

我遇到了这个问题,并感到困惑一分钟,直到我意识到,我不小心删除了我的bin文件夹。

如何解决此问题:

  1. 备份您的应用程序。
  2. cd退出Rails应用程序的根目录。
  3. 运行rails new name_of_your_app - 确保它与已存在的目录名称相同。
  4. Rails会重新生成文件夹,询问您是否要覆盖文件,每次询问时都会输入“no”,并且点击n
  5. Rails将添加缺少的bin文件,而如果您为其他所有内容点击n,它将保留其他所有内容。
  6. 在我的情况下,我使用HAML和application.html.haml文件,所以Rails也为我生成了一个application.html.erb文件,其中views/layouts我不需要,因此被删除。注意生成的任何其他文件并删除您不需要的任何文件。
  7. 运行rails s启动WEBrick服务器。