今日はN+1問題を直すために自分の環境にbullet
を導入してみた。
その時、すごいしょうもないミスで15分ほど潰してしまったのでもう繰り返さないように書き残しておく。
Gemfile.rb
group :deployment do
gem 'capistrano', '~> 3.4.0', require: false
gem 'capistrano-bundler', '~> 1.1.2', require: false
gem 'capistrano-figaro', require: false
gem 'capistrano-rails', '~> 1.1', require: false
gem 'capistrano-rbenv', '~> 2.0', require: false
gem 'capistrano3-unicorn', require: false
gem 'bullet'
end
この状態でbundle install
する。
そして、ネット記事とかREADMEとかを見てポップアップが出る程度の最低限の設定を追記
config/environments/development.rb
Rails.application.configure do
(省略)
config.after_initialize do
(省略)
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
end
(省略)
end
これでrails s
すると下記のようなエラー
xiting
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/config/environments/development.rb:18:in `block (2 levels) in <top (required)>': uninitialized constant Bullet (NameError)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:44:in `each'
(省略)
なんで?と10分くらい悩んだあと、
group :deployment do
に、bulletのgemを導入していたと気づく(なぜかdevelop
と見間違えていた、、、)
ので、修正して
Gemfile.rb
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
(省略)
gem 'bullet'
end
再度、rails s
する。
しかし結果が変わらない。
xiting
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/config/environments/development.rb:18:in `block (2 levels) in <top (required)>': uninitialized constant Bullet (NameError)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/vendor/bundle/ruby/2.4.0/gems/activesupport-4.2.8/lib/active_support/lazy_load_hooks.rb:44:in `each'
(省略)
なんでや!Gemfile直したやろ!とまた5分くらい悩む。
しばらく悩んだ後、あーと思ってbundle install
をし直す。
そして再度rails s
すると、、、
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxx92$ rs
=> Booting WEBrick
=> Rails 4.2.8 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
[2018-06-17 00:00:00] INFO WEBrick 1.3.1
[2018-06-17 00:00:00] INFO ruby 2.4.2 (2017-09-14) [x86_64-darwin15]
[2018-06-17 00:00:00] INFO WEBrick::HTTPServer#start: pid=26298 port=3000
直った!(当たり前)
Gemfileの記述を修正したら、bundle install
をし直さないと設定が反映されないという当たり前すぎることをうっかり忘れていた。
書くのも恥ずかしい内容ではあるが、gemの導入とかだとついconfigなどに問題があるのかと思いがちで基本的なことを忘れてしまうのでもう繰り返さないようにとりあえず残しておく。
こういうしょうもないのは一瞬で気づきたい。。。( 'ω' )