问题
I am developing rails 2.3.2 application.
When I type the command "rails script/server"
I got the following output instead of server starting why?
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.
When I type linux command "ls" I got the following directories and files showing:
app Capfile config criptq db doc features Gemfile Gemfile.lock generate lib log nbproject public Rakefile README script spec test tmp vendor
my Gemfile is:
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
回答1:
In a Rails 2.3 app it is just ./script/server start
回答2:
For rails 3.2.3 and latest version of rails you can start server by:
First install all gem with command: bundle install
or bundle
.
Then Configure your database to the database.yml
.
Create new database: rake db:create
Then start rails server. rails server
orrails s
回答3:
For rails 2.3.2 you can start server by:
ruby script/server
回答4:
Make sure you're in the right directory when you start the server
sites>yoursite> rails s
回答5:
In rails 2.3.x application you can start your server by following command:
ruby script/server
In rails 3.x, you need to go for:
rails s
回答6:
Rails version < 2
From project root run:
./script/server
回答7:
On rails 3, the simpliest way is rails s
.
In rails 2, you can use ./script/server start
.
You can also use another servers, like thin or unicorn, that also provide more performance.
I use unicorn, you can easily start it with unicorn_rails
.
BTW, if you use another things, like a worker (sidekiq, resque, etc), I strongly recommend you to use foreman, so you can start all your jobs in one terminal windows with one command and get a unified log.
回答8:
For newest Rails versions
If you have trouble with rails s
, sometimes terminal fails.
And you should try to use:
./bin/rails
To access command.
回答9:
For rails 4.1.4 you can start server:
$ bin/rails server
回答10:
For the latest version of Rails (Rails 5.1.4 released September 7, 2017), you need to start Rails server like below:
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
More help information:
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"
回答11:
If you are in rails2 version then to start the server you have do,
script/server
or
./script/server
But if you are in rails3 or above version then to start the server you have do,
rails server
or
rails s
回答12:
in rails 2.3.X,just type following command to start rails server on linux
script/server
and for more help read "README" file which is already created in rails project folder
回答13:
I also faced the same issue, but my fault was that I was running "rails s" outside of my application directory. After opening the cmd, just go inside your application and run the commands from their, it worked for me.
回答14:
Goto root directory of your rails project
- In rails 2.x run >
ruby script/server
- In rails 3.x use >
rails s
回答15:
You have to cd to your master directory and then rails s command will work without problems.
But do not forget bundle-install command when you didn't do it before.
回答16:
run with nohup to run process in the background permanently if ssh shell is closed/logged out
nohup ./script/server start > afile.out 2> afile.err < /dev/null &
来源:https://stackoverflow.com/questions/7526424/how-to-start-rails-server