LoginSignup
2
0

More than 5 years have passed since last update.

Gem導入の際のしょうもないミス備忘録

Last updated at Posted at 2018-06-07

今日は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などに問題があるのかと思いがちで基本的なことを忘れてしまうのでもう繰り返さないようにとりあえず残しておく。
こういうしょうもないのは一瞬で気づきたい。。。( 'ω' )

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0