如何启动rails服务器?

我正在开发rails 2.3.2应用程序。

当我输入命令“ rails script / server ”时

我得到以下输出而不是服务器启动为什么?

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 

在Rails 2.3应用程序中,它只是./script/server start

对于rails 3.2.3和最新版本的rails,您可以通过以下方式启动服务器:
首先使用命令安装所有gem: bundle installbundle
然后将数据库配置为database.yml
创建新数据库: rake db:create
然后启动rails服务器。
rails serverrails s

对于rails 2.3.2,您可以通过以下方式启动服务器

 ruby script/server 

启动服务器时,请确保您位于正确的目录中

sites> yoursite> rails s

在rails 2.3.x应用程序中,您可以通过以下命令启动服务器:

ruby script/server

在rails 3.x中,您需要选择:

rails s

Rails版本<2
从项目根运行:

 ./script/server 

在轨道3上,最简单的方法是rails s 。 在rails 2中,您可以使用./script/server start

您还可以使用其他服务器,如瘦或独角兽 ,也可以提供更高的性能。

我使用独角兽,你可以用unicorn_rails轻松启动它。

顺便说一句,如果你使用其他东西,比如工人(sidekiq,resque等),我强烈建议你使用工头 ,这样你就可以用一个命令在一个终端窗口中启动所有工作并获得一个统一的日志。

对于最新的Rails版本

如果您在使用rails s遇到问题,有时终端会失败。

你应该尝试使用:

 ./bin/rails 

访问命令。

对于rails 4.1.4,您可以启动服务器:

$ bin / rails服务器

如果您使用的是rails2版本,那么启动您所使用的服务器,

script/server

 ./script/server 

但是如果您使用的是rails3或更高版本,那么启动您所使用的服务器,

rails server

 rails s 

在rails 2.3.X中,只需输入以下命令即可在linux上启动rails服务器

 script/server 

有关更多帮助,请阅读已在rails项目文件夹中创建的“README”文件

我也面临同样的问题,但我的错是我在应用程序目录之外运行“rails s”。 打开cmd后,只需进入你的应用程序并运行他们的命令,它对我有用。

对于最新版本的Rails(2017年9月7日发布的Rails 5.1.4 ),您需要启动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" 

转到rails项目的根目录

  • 在rails 2.x中运行> ruby script/server
  • 在rails 3.x中使用> rails s

如果关闭/注销ssh shell,则使用no​​hup运行以永久地在后台运行进程

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