Ruby on rails 如何启动rails服务器?
我正在开发rails 2.3.2应用程序 当我键入命令“railsscript/server”时 我得到了以下输出而不是服务器启动为什么Ruby on rails 如何启动rails服务器?,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我正在开发rails 2.3.2应用程序 当我键入命令“railsscript/server”时 我得到了以下输出而不是服务器启动为什么 rails script/server Usage: rails new APP_PATH [options] Options: -J, [--skip-javascript] # Skip JavaScript files [--dev] # Setup the application
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
我的文件是:
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应用程序中,对于Rails 3.2.3和最新版本的Rails,您可以通过以下方式启动服务器:
首先使用以下命令安装所有gem:
bundle install
或bundle
然后将数据库配置为
数据库.yml
创建新数据库:
rakedb:Create
然后启动rails服务器
对于rails 2.3.2,您可以通过以下方式启动服务器:
ruby script/server
在rails 3上,最简单的方法是
rails s
。
在rails 2中,您可以使用/script/server start
您还可以使用其他服务器,如或,以提供更高的性能
我使用unicorn,您可以很容易地从unicorn\u rails
开始
顺便说一句,如果您使用其他东西,如worker(sidekiq、resque等),我强烈建议您使用,这样您就可以使用一个命令在一个终端窗口中启动所有作业,并获得统一的日志。转到rails项目的根目录
- 在rails 2.x中运行>
ruby脚本/server
- 在rails 3.x中,使用>
rails s
ruby脚本/服务器
在rails 3.x中,您需要:
rails s
启动服务器时,确保您位于正确的目录中
sites>yoursite>rails s如果您使用的是rails2版本,则要启动您所拥有的服务器
脚本/服务器
或
./script/server
rails s
但是如果您使用的是rails3或更高版本,那么要启动您所拥有的服务器
rails服务器
或
./script/server
rails s
对于最新的Rails版本
如果您在使用rails时遇到问题,有时终端会出现故障
您应该尝试使用:
./bin/rails
访问命令。对于rails 4.1.4,您可以启动服务器:
$bin/rails server在rails 2.3.X中,只需键入以下命令即可在linux上启动rails服务器
script/server
要获得更多帮助,请阅读已经在rails项目文件夹中创建的“自述”文件,如果ssh外壳关闭/注销,请使用nohup在后台永久运行该进程
nohup ./script/server start > afile.out 2> afile.err < /dev/null &
nohup./script/server start>afile.out 2>afile.err
我也面临同样的问题,但我的错误是我在应用程序目录之外运行“rails s”。
打开cmd后,只需进入应用程序内部并从他们的应用程序运行命令,这对我很有用 对于最新版本的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"
Rails版本<2从项目根运行:
./script/server
您必须将cd刻录到主目录,rails的命令才能正常工作
但是不要忘记以前没有执行过的bundle install命令。我相信如果“rails new[project]”没有正确执行,就会出现这种情况。如果您在windows上执行此操作,并且“rails服务器”仅返回帮助屏幕,则可能需要重新启动命令提示符窗口,并可能重复安装说明。如果这是您第一次设置环境,则更可能出现这种情况。我猜您键入此内容时不在应用程序文件夹中。您的意思是我应该转到“应用程序”文件夹吗?我试过了,但得到了相同的结果否,在你的rails应用程序的根目录下。@a开始时,正如你所见,“ls”命令的输出显示我在我的rails应用程序的根目录下。@Nicklasos,我更新了我的帖子,正如你所见,我的GEM文件显示我正在使用rails 2.3.2“ruby脚本/服务器”和“/script/server start”都在工作:)它应该说什么时候启动:在端口3000上启动webrick或者其他什么。你可以通过在Ubuntu/Debian中添加-p 8088或类似的东西来改变这一点,它只是在BeagleBone Black$/script/server上测试的。/script/server start sh:vendor/plugins/blackbox\u services/script/start\u thin.rb:没有这样的文件或目录在安装完所有缺失的gem之前(linux):
bundle install