2011-09-23 94 views
25

我正在開發rails 2.3.2應用程序。如何啓動rails服務器?

當我鍵入命令「軌腳本/服務器

我得到了以下輸出,而不是服務器開始,爲什麼?

rails script/server 
Usage: 
    rails new APP_PATH [options] 

Options: 
    -J, [--skip-javascript]  # Skip JavaScript files 
     [--dev]     # Setup the application with Gemfile pointing to your Rails checkout 
     [--edge]     # Setup the application with Gemfile pointing to Rails repository 
    -G, [--skip-git]    # Skip Git ignores and keeps 
    -m, [--template=TEMPLATE]  # Path to an application template (can be a filesystem path or URL) 
    -b, [--builder=BUILDER]  # Path to a application builder (can be a filesystem path or URL) 
     [--old-style-hash]   # Force using old style hash (:foo => 'bar') on Ruby >= 1.9 
     [--skip-gemfile]   # Don't create a Gemfile 
    -d, [--database=DATABASE]  # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) 
           # Default: sqlite3 
    -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 
    -r, [--ruby=PATH]    # Path to the Ruby binary of your choice 
           # Default: /home/xichen/.rvm/rubies/ruby-1.8.7-p352/bin/ruby 
    -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library 
           # Default: jquery 

Runtime options: 
    -q, [--quiet] # Supress status output 
    -s, [--skip]  # Skip files that already exist 
    -f, [--force] # Overwrite 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. 

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. 

當我鍵入linux命令 「LS」 我得到了下面的目錄和文件顯示:

app Capfile config criptq db doc features Gemfile Gemfile.lock generate lib log nbproject public Rakefile README script spec test tmp vendor 

的Gemfile是:

source "http://rubygems.org" 

gem "rails", "2.3.2" 
gem "mysql", "2.8.1" 
gem "fastercsv" 
gem "will_paginate", "2.3.16" 
gem "chronic", "0.6.4" 
gem "whenever", "0.4.1" 
gem "searchlogic", "2.4.28" 

group :development do 
    gem "mongrel", "1.1.5" 
end 

group :test do 
    gem "rspec", "1.3.2" 
    gem "rspec-rails", "1.3.4" 
    gem "factory_girl", "1.3.3" 
end 
+4

當你輸入這個 – apneadiving

+0

我猜你不在你的應用程序的文件夾你的意思是我應該去「應用程序」文件夾?我試過了,但我得到了相同的結果 – Leem

+0

不,在你的rails應用程序的根目錄下。 – apneadiving

回答

24

在Rails 2.3的應用程序它只是./script/server start

+1

」紅寶石腳本/服務器「和」./script/server啓動「都工作:) – Leem

+0

它應該說什麼時候開始:啓動webrick在端口3000或什麼。通過添加-p 8088或類似的東西 –

+1

在Ubuntu/Debian中,它只是'./script/server' - 在BeagleBone黑色上測試 – TekuConcept

22

爲Rails 3.2.3和最新版本的rails可以通過以下方式啓動服務器:
首先安裝所有帶命令的gem:bundle installbundle
然後將您的數據庫配置爲database.yml
創建新的數據庫:rake db:create
然後啓動軌道服務器。
rails serverrails s

+0

只有在安裝了所有缺少的gem(linux)後才能正常工作:'bundle install' – TekuConcept

6

爲Rails 2.3.2您可以通過以下方式啓動服務器:

ruby script/server 
3

在軌道3,simpliest方式是rails s。 在導軌2中,您可以使用./script/server start

您也可以使用其他的服務器,像thinunicorn,也提供了更多的性能。

我用麒麟,你可以很容易地unicorn_rails啓動它。如果你使用其他東西,比如工人(sidekiq,resque等),我強烈建議你使用foreman,這樣你就可以用一個命令在一個終端窗口啓動你的所有工作,並獲得一個統一的日誌。

1
您的軌道

轉到根目錄項目

  • 在軌運行2.X>在軌2.X
  • 在軌3.x中,使用使用的情況下,紅寶石腳本/服務器>軌小號
5

在Rails 2.3.x版本的應用程序,你可以開始下面的命令服務器:

ruby script/server

在導軌3中。X,你需要去:

rails s

6

確保你在正確的目錄裏,當你啓動服務器

網站> yoursite>軌道小號

+0

像我這樣的所有noobs都需要這個!謝謝。 –

1

如果你在rails2版本,那麼開始你必須做服務器,

script/server

./script/server 

但如果你是在Rails3中或以上版本,然後開始你必須做服務器,

rails server

rails s 
2

對於最新的Rails版本

如果你有rails s麻煩,有時終端失敗。

你應該嘗試使用:

./bin/rails 

要訪問命令。

2

爲Rails 4.1.4就可以啓動服務器:

$斌在軌2.3.x版本/導軌服務器

1

,只需鍵入以下命令在Linux上

script/server 

啓動軌道服務器並獲得更多幫助閱讀已在軌道項目文件夾中創建的「README」文件

0

如果ssh shell已關閉/註銷,則使用no​​hup運行以永久運行後臺進程

nohup ./script/server start > afile.out 2> afile.err < /dev/null & 
1

我也面臨同樣的問題,但我的錯是我在我的應用程序目錄之外運行「rails s」。 打開cmd後,進入你的應用程序並從它們運行命令,它爲我工作。

1

對於Rails開發的最新版本(的Rails 5.1.4 2017年9月7日發佈),你需要啓動Rails的服務器如下圖所示:

hello_world_rails_project$ ./bin/rails server 

=> Booting Puma 
=> Rails 5.1.4 application starting in development 
=> Run `rails server -h` for more startup options 
Puma starting in single mode... 
* Version 3.10.0 (ruby 2.4.2-p198), codename: Russell's Teapot 
* Min threads: 5, max threads: 5 
* Environment: development 
* Listening on tcp://0.0.0.0:3000 

更多幫助信息:

hello_world_rails_project$ ./bin/rails --help 

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") 
test   Run tests except system tests (short-cut alias: "t") 
test:system Run system tests 
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"