简体   繁体   English

命令:rails console,生成无法识别。 错误:无法识别命令“ rails”用法:rails COMMAND [ARGS]

[英]Command: rails console, generate not recognize. Error: Command 'rails' not recognized Usage: rails COMMAND [ARGS]

When I go to rails folder (I'm inside my rails app folder) and type "rails c" or "rails g" it said: 当我转到rails文件夹(位于我的rails应用程序文件夹中)并键入“ rails c”或“ rails g”时,它说:

Error: Command 'rails' not recognized 错误:无法识别命令“ rails”

Usage: rails COMMAND [ARGS] 用法:导轨COMMAND [ARGS]

Usage: spring COMMAND [ARGS]                                                                                                                     

Commands for spring itself:                                                                                                                      

  binstub         Generate spring based binstubs. Use --all to generate a binstub for all known commands. Use --remove to revert.                
  help            Print available commands.                                                                                                      
  server          Explicitly start a Spring server in the foreground                                                                             
  status          Show current status.                                                                                                           
  stop            Stop all spring processes for this project.                                                                                    

Commands for your application:                                                                                                                   

  rails           Run a rails command. The following sub commands will use spring: console, runner, generate, destroy, test.                     
  rake            Runs the rake command                                                                                                          
Error: Command 'rails' not recognized                                                                                                            
Usage: rails COMMAND [ARGS]                                                                                                                      

The most common rails commands are:                                                                                                              
 generate    Generate new code (short-cut alias: "g")                                                                                            
 console     Start the Rails console (short-cut alias: "c")                                                                                      
 server      Start the Rails server (short-cut alias: "s")                                                                                       
 dbconsole   Start a console for the database specified in config/database.yml                                                                   
             (short-cut alias: "db")                                                                                                             
 new         Create a new Rails application. "rails new my_app" creates a                                                                        
             new application called MyApp in "./my_app"                                                                                          

In addition to those, there are:                                                                                                                 
 destroy      Undo code generated with "generate" (short-cut alias: "d")                                                                         
 plugin new   Generates skeleton for developing a Rails plugin                                                                                   
 runner       Run a piece of code in the application environment (short-cut alias: "r")                                                          

All commands can be run with -h (or --help) for more information.

I'm running Linux Subsystem for Windows 10, I know I know you see Windows but it's kind of... Linux, and I installed Ruby by rbenv through this tutorial . 我正在运行Windows 10的Linux子系统,我知道我知道您会看到Windows,但它有点... Linux,我通过本教程通过rbenv安装了Ruby。

Try this command from your app folder: 在您的应用文件夹中尝试以下命令:

rake rails:update:bin

Say y to replace the binaries. 说y替换二进制文件。

I had the same problem using rails with Windows Linux Subsystem. 在Windows Linux子系统中使用rails时,我遇到了同样的问题。 I found the suggestion here: 我在这里找到了建议:

Rails command Error Rails命令错误

I tried it and it solved my problem, so maybe yours as well. 我尝试了一下,它解决了我的问题,也许也是您的问题。

Even though the accepted answer solved your issue, I want to add another because I ran into the same error message but the underlying issue and my environment setup wasn't the same. 即使已接受的答案解决了您的问题,我也想添加另一个,因为我遇到了相同的错误消息,但是根本的问题和我的环境设置不一样。 However, recreating the executables in my app's bin folder did not solve the problem. 但是,在应用程序的bin文件夹中重新创建可执行文件并不能解决问题。

The issue: When I tried running bundle exec rails s or bundle exec rails c I got the same error as posted in the question. 问题:当我尝试运行bundle exec rails sbundle exec rails c ,出现了与问题中所发布的错误相同的错误。 Using the apps executables worked fine though ./bin/rails s . 使用应用程序可执行文件可以通过./bin/rails s正常工作。

So the main differences from the question: I was using bundle exec when I got the error. 因此,与问题的主要区别在于:出现错误时,我正在使用bundle exec

What was happening behind the scenes: bundle exec rails s was calling this executable /Users/robin/.rvm/gems/ruby-2.3.8/bin/rails which is shipped by the railties gem. 幕后发生的事情: bundle exec rails s调用了该可执行文件/Users/robin/.rvm/gems/ruby-2.3.8/bin/rails ,该文件由railties gem交付。 I found this file was overwritten due to a gem which had an executable rails defined in its .gemspec . 我发现此文件由于gem的.gemspec定义了一个可执行的rails而被覆盖。

What solved my problem: 什么解决了我的问题:

Running $ bundle pristine railties ( https://bundler.io/v2.0/man/bundle-pristine.1.html ) so railties would be reset and with that the executable shipped by railties would overwrite the wrong one. 运行$ bundle pristine railtieshttps://bundler.io/v2.0/man/bundle-pristine.1.html ),这样将重置railties,并且由railties交付的可执行文件将覆盖错误的可执行文件。

Addition: Of course it only helps as long as the intrusive gem shipping a rails executable is also updated and no longer wants it to be installed. 补充:当然,只有在附带rails可执行文件的侵入式宝石也被更新并且不再希望安装它的情况下,它才有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM