2011-09-23 95 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"