Bash on Ubuntu on Windows(wsltty)上にrbenvでRoRの環境を作り、rails c
やrails g model hogehoge
を実行したら以下のエラーが発生した。
$ rails c Version: 2.0.1 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.
直し方は以下のサイトに書いてあった。 stackoverflow.com この質問の回答によると、以下のコマンドを実行すれば良いとのこと。
rake rails:update:bin
無事にrailsコマンドが正常に動作するようになった。
原因だが、Macで作ったRailsプロジェクトをリポジトリから取得して作業したためbin/railsがそのまま使われており、おそらくそれでプラットフォームの違いがあり正常動作しなかったと思われる。