Rails 4.1.8 でbundle execを省略しようとしてハマった件
Rails 4.1.8 でbundle execを省略しようとしてハマった件
基本的にRails4系から変わった挙動の問題
- 今までは
rails
コマンドやrake
コマンドはscripts/
にあった - Rails4系から
bin/
に移ってきた bundle install --binstubs
がデフォのrails
rake
を上書きしてしまう
起きる現象
サーバの起動はできるけどこんな警告がでる
$ rails s Looks like your app's ./bin/rails is a stub that was generated by Bundler. In Rails 4, your app's bin/ directory contains executables that are versioned like any other source code, rather than stubs that are generated on demand. Here's how to upgrade: bundle config --delete bin # Turn off Bundler's stub generator rake rails:update:bin # Use the new Rails 4 executables git add bin # Add bin/ to source control You may need to remove bin/ from your .gitignore as well. When you install a gem whose executable you want to use in your app, generate it and add it to source control: bundle binstubs some-gem-name git add bin/new-executable => Booting WEBrick => Rails 4.1.8 application starting in development on http://0.0.0.0:3000 => Run `rails server -h` for more startup options => Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option) => Ctrl-C to shutdown server
解決策
個別に bundle binstubs する
- めんどい。
rbenv-binstubs を使う
bundle_bin
ディレクトリがなんか違和感あるけど、とりあえずこれが楽
rbenv-binstubs
をインストールする
$ mkdir -p ~/.rbenv/plugins $ cd ~/.rbenv/plugins $ git clone https://github.com/ianheggie/rbenv-binstubs.git
bundle_bin
ディレクトリを作る
$ bundle install --binstubs=bundle_bin $ rbenv rehash
これで .bundle/config
に以下の設定が追加されて、
$ cat .bundle/config --- ... BUNDLE_BIN: bundle_bin
rbenv-binstubs
はこれを読みに行ってくれるはず。