如何运行"rails s"命令

9

我在Ubuntu上运行rails s时遇到了问题。当我输入rails s时,它不会启动服务器,而是输出:

kyala@ubuntu:~/depot$ rails s

Usage:
  rails new APP_PATH [options]

Options:
  
-r, [--ruby=PATH]           # Path to the Ruby binary of your choice
                              # Default: /home/kyala/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
  
-d, [--database=DATABASE]   # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db)enter code here
                              # Default: sqlite3
 
 -b, [--builder=BUILDER]     # Path to an application builder (can be a filesystem path or URL)
  
-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
      [--edge]                # Setup the application with Gemfile pointing to Rails 

repository
      
[--skip-gemfile]        # Don't create a Gemfile
 
 -O, [--skip-active-record]  # Skip Active Record files
 
 -T, [--skip-test-unit]      # Skip Test::Unit files
 
 -J, [--skip-prototype]      # Skip Prototype files
 
 -G, [--skip-git]            # Skip Git ignores and keeps


Runtime options:
 
-f, [--force]    # Overwrite files that already exist
  
-p, [--pretend]  # Run but do not make any changes
 
 -q, [--quiet]    # Supress status output
 
 -s, [--skip]     # Skip files that already exist


Rails options:
 
 -v, [--version]  # Show Rails version number and quit

  -h, [--help]     # Show this help message 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.
13个回答

7
尝试重新生成binstubs:
rm bin/*
rake rails:update:bin

它应该能解决问题。

对于更新的(5.2+)Rails版本,请使用

rake app:update:bin

Rails 5.0.0.1 我必须运行 bin/rails app:update:bin。你知道为什么会发生这种情况吗?我创建了一个新的分支,检出它,做了一些工作,回到主分支,突然间我不能再运行 rails server 了。 - rmcsharry

6
当Rails应用程序文件夹中缺少脚本文件夹时,会显示上述错误。
我只是从另一个应用程序中复制了它,对我很有效。

3
在运行Rails服务器之前,您需要先创建一个Rails应用程序。
例如,要创建一个名为“test_app”的新应用程序,请运行以下命令:
rails new test_app

当您创建了应用程序后,可以进入目录并启动服务器:

cd test_app
rails server

我已经创建了一个新的 Rails 应用程序,但每次我想运行 rails s 时它都会给我显示那个消息 :(。 - kYaLa OplAdO
which rails 的输出是什么? - rdvdijk
这是输出 /home/kyala/.rvm/gems/ruby-1.9.2-p290/bin/rails - kYaLa OplAdO

2

我的第一反应是您不在Rails应用程序的根目录中。

在我们的部署服务器上,我必须键入

./script/rails s

当我在Rails应用的根目录时,出现了问题。我认为这是因为那里不知道bin\rails
如果这样行不通,那么似乎你根本不在Rails根目录中,这也可以解释为什么rails s无法工作。
一个Rails根项目至少包含以下目录:applibconfigscript ....

它给我这个错误:kyala@ubuntu:~/depot$ ./script/rails s bash: ./script/rails: 没有那个文件或目录 - kYaLa OplAdO
那么看来你现在位于一个Rails应用程序中,在一个标准的Rails应用程序中,有一个包含rails脚本的script文件夹。你能验证一下自己是否位于一个Rails应用程序中吗?它包含哪些文件夹? - nathanvda

2

好的,仅供参考... 当我们删除Rails应用程序中的一些(主要是脚本)文件夹时,才会出现这个问题... (可能是...意外发生)。我遇到过这个问题,但是在错误的应用程序文件夹中...


0
在你的项目文件夹内运行以下命令:
rails s

你的项目文件夹包含 node_modulesGemfile.lock 等等...


0

我们遇到了同样的问题。

请确保在脚本文件夹中运行“rails”命令,而不是不同的二进制“rails”命令。

script/rails s

如果你进入脚本文件夹并运行命令,它就和这个一样:

cd script
./rails s

0

在自己寻找答案的过程中,我尝试了一些对我有用的方法来让rails s正常工作。这导致了658个文件的更改,102204个插入和149个删除。

  1. 通过运行 ls 命令查看当前所在的文件。
  2. 运行 git status 命令。
  3. 运行 git add . 命令。
  4. 运行 git commit -m "记录你要添加到 Github 仓库的更改内容" 命令。
  5. 我尝试运行 git pushgit push master 命令,但都无法工作,“想象一下”。我猜测你不能推送属于不同文件或分支的更改。
  6. 这是秘密...由于某种奇怪的原因,我正在另一个文件中工作,所以我必须运行 git pull YourOtherFile 命令。这就是一切开始变得有意义的地方。
  7. 现在,我再次运行 git status 命令,以了解此文件中发生了什么。有修改和未跟踪的内容。
  8. 接下来,cd 回到另一个文件。
  9. 运行 git status 命令,查看所有已修改和未跟踪的文件。
  10. 运行 git add .git commit -m "记录你对此仓库的更改" 命令。
  11. 看魔法发生,然后运行 git push 命令。
  12. 运行 gem update bundler 命令。
  13. 然后我运行了 gem install rails_12factor 命令。
  14. 再次运行 git status 命令,查看你的修改。
  15. 运行 git commit -m "成功添加 gem rails_12Factor" 命令。
  16. 运行 git push 命令。
  17. 我遇到了 bcrypt 被锁定在 3.1.11 的问题,所以我运行了 gem install 'bcrypt' 命令。
  18. 再次运行 gem install rails_12factor 命令。我相信我将“factor”中的“f”大写了。
  19. 运行 gem update 命令。
  20. 运行 gem install pg 命令。
  21. 运行 git add . 命令。
  22. 运行 git commit -m "更新 Gemfile" 命令。
  23. 运行 git push 命令。
  24. 再次运行 gem install 'pg' 命令。
  25. 我遇到了各种问题,但这是因为我试图将我的 gemfile 升级到 Rails 5。
  26. 运行 gem install railties 命令。
  27. 运行 gem install activesupport 命令。
  28. 如果你的 Gemfile 已经在另一个版本的 Rails 中(gem 'rails','4.2.6'),请确保将其保留在那里,因为 Rails 5 没有显着的差异。

0

检查您的应用程序结构中是否存在“script”文件夹。


0

我曾经遇到过同样的问题。在创建应用程序后,我忘记运行bundle命令。

请从项目目录的根目录运行以下命令:

bundle install 

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