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

时间:2016-08-12 04:07:08

标签: ruby-on-rails ruby windows ubuntu

当我进入rails文件夹(我在我的rails app文件夹中)并输入“rails c”或“rails g”时,它说:

错误:命令'rails'无法识别

用法:rails 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.

我正在运行适用于Windows 10的Linux子系统,我知道我知道你看到了Windows但它有点...... Linux,我通过rbenv通过this tutorial安装了Ruby。

2 个答案:

答案 0 :(得分:6)

从您的应用程序文件夹中尝试此命令:

rake rails:update:bin

说y替换二进制文件。

我在Windows Linux子系统中使用rails时遇到了同样的问题。我在这里找到了这个建议:

Rails command Error

我尝试了它,它解决了我的问题,所以也许你的问题。

答案 1 :(得分:0)

即使接受的答案解决了您的问题,我也想添加另一个,因为我遇到了相同的错误消息,但是潜在的问题和我的环境设置不相同。但是,在应用程序的bin文件夹中重新创建可执行文件并不能解决问题。

问题:当我尝试运行bundle exec rails sbundle exec rails c时,遇到与问题中相同的错误。通过./bin/rails s,使用应用可执行文件可以正常工作。

因此与问题的主要区别在于:出现错误时我正在使用bundle exec

幕后发生的事情:bundle exec rails s调用了Railties gem随附的可执行文件/Users/robin/.rvm/gems/ruby-2.3.8/bin/rails。我发现该文件由于gem的rails中定义的可执行文件.gemspec而被覆盖。

什么解决了我的问题:

运行$ bundle pristine railtieshttps://bundler.io/v2.0/man/bundle-pristine.1.html),以便重新设置安全栅,并且安全栅附带的可执行文件将覆盖错误的可执行文件。

添加:当然,只有在运送rails可执行文件的侵入性宝石也被更新且不再希望安装它的情况下,它才有用。