【问题标题】:Rails server does not start by command "Rails s"Rails 服务器不通过命令“Rails s”启动
【发布时间】:2019-05-22 20:52:35
【问题描述】:

我是 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 应用程序?
  • 是的,已经通过命令“rails new new_project”创建了应用程序。它是创建的:(

标签: ruby-on-rails ruby


【解决方案1】:

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

bundle exec rake rails:update:bin

【讨论】:

  • 谢谢,这真的很有帮助。在旧的 Rails 应用程序中找不到不工作的 rails 命令和工作的命令之间的区别。你能解释一下吗?为什么这个目录不见了?
  • 非常感谢先生!
  • 是的,我也很困惑为什么rails new 命令没有首先简单地创建由该命令创建的文件。 rails new 确实创建了 bin\bundlebin\setup,但没有创建 bin\railsbin\rake
【解决方案2】:
  1. 您需要创建一个新的 Rails 应用程序(除非您已经有一个)

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

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

    rails s
    

【讨论】:

  • 警告:这是 rails 3 格式。使用 rails 2,这将在当前目录中创建一个全新的 rails 应用程序!哟!
  • @fl00r 又一个错误来了,请你点击这个链接stackoverflow.com/questions/10057961/…
  • gem "therubyracer" 添加到您的Gemfile
【解决方案3】:

一旦你创建了项目并cd'd 进入它:

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

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

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

【讨论】:

  • "rails s" 是 3.x 版的一个很好的快捷方式 - 问题是他没有 cd 进入目录。
  • 当然,尽管使用 Rails 2 它会在他所在的任何目录中创建一个全新的 Rails 应用程序!
  • 你可以点击这个链接吗stackoverflow.com/questions/10057961/…
【解决方案4】:

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

【讨论】:

    【解决方案5】:

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

    如何解决:

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

    【讨论】:

    • 哇,我也删除了我的bin,非常困惑!谢谢!
    【解决方案6】:

    我也是 Ruby on rails 的新手。当我的电脑意外关机时,我发现了同样的问题。我按照以下步骤修复它。

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

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

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

    4. 将 New bin 文件夹从 Demo App 粘贴到旧 App。

    5. 启动服务器 Rails 服务器

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-20
      • 2016-10-01
      • 1970-01-01
      • 2015-08-07
      • 2016-11-19
      • 1970-01-01
      • 2012-12-12
      • 1970-01-01
      相关资源
      最近更新 更多