2012-04-07 73 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服務器。