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

14

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

你安装了哪个版本的Rails?你已经创建了一个新的Rails应用程序吗? - alex
是的,已经通过命令“rails new new_project”创建了应用程序...它已经被创建了 :( - Gihan Dilusha
6个回答

34

更好的方法是使用以下命令更新您的存储箱

bundle exec rake rails:update:bin

1
谢谢,这真的帮了我很多。在旧的Rails应用程序中找不到不起作用的rails命令和工作的命令之间的区别。你能解释一下吗?为什么这个目录会丢失? - Sebastian Wramba
非常感谢您,先生! - user1955009
是的,我也很困惑为什么rails new命令一开始没有直接创建该命令所创建的文件。 rails new确实创建了bin\bundlebin\setup,但没有创建bin\railsbin\rake - Teemu Leisti

11
  1. 你需要创建一个新的 Rails 应用程序(如果你还没有)

rails new my_app
前往您的应用程序目录。
cd my_app
  • 在该目录下启动服务器

  • rails s
    

    2
    警告:这是Rails 3格式。在Rails 2中,这将在当前目录内创建一个全新的Rails应用程序!哇! - Michael Durrant
    @fl00r 又出现了另一个错误 请你跟随这个链接 https://dev59.com/YWLVa4cB1Zd3GeqPwXEv - Gihan Dilusha
    gem "therubyracer" 添加到您的 Gemfile 中。 - fl00r

    5

    创建项目并进入项目后:

    如果你使用的是Rails 2.x版本,请使用script/server

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

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


    "rails s" 是版本 3.x 的一个好用的快捷方式 - 问题在于他没有进入目录。 - Sprachprofi
    当然可以,不过使用Rails 2时,它会在当前目录下创建一个全新的Rails应用程序! - Michael Durrant
    请问您能否跟随此链接:https://dev59.com/YWLVa4cB1Zd3GeqPwXEv - Gihan Dilusha

    1
    我也是Ruby on Rails的新手。当我的电脑意外关机时,我遇到了同样的问题。我按照以下步骤修复它:
    1. 创建一个新应用程序。 Rails new demo --Database=postgresql

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

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

    4. 将新的bin文件夹从Demo应用程序粘贴到旧的应用程序中。

    5. 启动服务器 Rails server

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


    1
    在启动Rails服务器之前,您必须进入应用程序的目录。这是因为服务器需要知道它应该服务于哪个应用程序。

    1
    我遇到了这个问题,有一会儿感到困惑,直到意识到我不小心删除了我的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服务器。

    1
    哇,我也删了我的 bin 目录,当时非常困惑!谢谢! - duhaime

    网页内容由stack overflow 提供, 点击上面的
    可以查看英文原文,
    原文链接