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

时间:2012-04-07 12:16:35

标签: ruby-on-rails ruby

我是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

6 个答案:

答案 0 :(得分:31)

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

更新您的bin
bundle exec rake rails:update:bin

答案 1 :(得分:9)

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

    rails new my_app
    
  2. 转到您的应用目录

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

    rails s
    

答案 2 :(得分:5)

创建项目并cd进入项目后:

如果您使用的是rails 2.x

,请使用script/server

如果您使用的是rails 3.x

,请使用script/rails server

如果您使用的是rails 4.x

,请使用bin/rails server

答案 3 :(得分:1)

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

答案 4 :(得分:1)

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

如何修复它:

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

答案 5 :(得分:0)

我也是Ruby on Rails的新手。意外关闭PC时,我发现相同的问题。我会按照以下步骤修复它。

  1. 创建一个新的应用程序。 Rails的新演示--Database = postgresql

  2. 复制新演示应用程序的Bin文件夹。

  3. 删除旧应用的Bin文件夹(显示错误)

  4. 将“新bin”文件夹从演示应用粘贴到旧应用。

  5. 启动服务器 Rails服务器

请注意,您可以从Github复制bin文件夹。 https://github.com/hoovercj/depot