Rails服务器无法通过命令“Rails s”启动

我是ruby和rails的新手,我在ubuntu中安装了rails。 但是当我通过键入“rails s”进入启动服务器时,它不会启动并跟随消息。 但我可以通过命令rails new new_project创建一个新项目。 请rails专家帮帮我。

root@ubuntu:~# rails s Usage: rails new APP_PATH [options] Options: -j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library # Default: jquery -m, [--template=TEMPLATE] # Path to an application template (can be a filesystem path or URL) [--dev] # Setup the application with Gemfile pointing to your Rails checkout -J, [--skip-javascript] # Skip JavaScript files [--edge] # Setup the application with Gemfile pointing to Rails repository -G, [--skip-git] # Skip Git ignores and keeps -d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) # Default: sqlite3 -b, [--builder=BUILDER] # Path to a application builder (can be a filesystem path or URL) -r, [--ruby=PATH] # Path to the Ruby binary of your choice # Default: /usr/bin/ruby1.8 [--old-style-hash] # Force using old style hash (:foo => 'bar') on Ruby >= 1.9 [--skip-gemfile] # Don't create a Gemfile -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 Runtime options: -q, [--quiet] # Supress status output -f, [--force] # Overwrite files that already exist -s, [--skip] # Skip 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. You can specify extra command-line arguments to be used every time 'rails new' runs in the .railsrc configuration file in your home directory. Note that the arguments specified in the .railsrc file don't affect the defaults values shown above in this help message. 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 

  1. 您需要创建一个新的Rails应用程序(除非您已经有一个)

     rails new my_app 
  2. 转到您的app目录

     cd my_app 
  3. 在该目录中启动服务器

     rails s 

更好的方法是使用以下命令更新bin

 bundle exec rake rails:update:bin 

一旦你创建了项目并cd进去了:

如果您使用的是rails 2.x版,请使用script/server

如果您使用的是rails 3.x版,请使用script/rails server

如果您使用的是rails 4.x版本,请使用bin/rails server

在启动rails服务器之前,您必须进入应用程序的目录。 那是因为服务器需要知道它应该服务的应用程序。

我遇到了这个问题并且混淆了一分钟,直到我意识到我不小心删除了我的bin文件夹。

如何解决:

  1. 备份您的应用。
  2. cd退出Rails应用程序的根目录。
  3. 运行rails new name_of_your_app – 确保它与已存在的目录名称相同。
  4. Rails将再次构建文件夹,询问您是否要覆盖文件,每次询问时都会为“否”命中n
  5. Rails将添加丢失的bin文件,而如果你为其他所有内容命中n ,它将保留其他所有内容。
  6. 在我的情况下,我使用HAML和application.html.haml文件,因此Rails也在views/layouts为我生成了一个application.html.erb文件,我不需要这样删除。 注意生成的任何其他文件并删除任何您不想要的文件。
  7. 运行rails s以启动WEBrick服务器。