RailsでgemのBulletを使用しようとしたところ、エラーが出て困りました。
BulletはN+1問題のログを出力してくれたりする便利gemです。Gemfileに書いてbundle install
をした後に公式のままでやってみたところエラーがでました。
Bulletの設定をdevelopment.rbに記述
Github : https://github.com/flyerhzm/bullet
上記にはdevelopment.rbにconfig.after_initialize
を書くようにあります。
development.rbに追記
vi config/environments/development.rb
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.growl = true
Bullet.xmpp = { :account => 'bullets_account@jabber.org',
:password => 'bullets_password_for_jabber',
:receiver => 'your_account@jabber.org',
:show_online_status => true }
Bullet.rails_logger = true
Bullet.honeybadger = true
Bullet.bugsnag = true
Bullet.airbrake = true
Bullet.rollbar = true
Bullet.add_footer = true
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
Bullet.slack = { webhook_url: 'http://some.slack.url', foo: 'bar' }
end
development.rbに上記を記述したところエラーがでるようになりました。
rails sがエラー
rails s
でサーバーを立ち上げようとするとエラーがでてしまいます。
serverがスタートできない
bundle exec rails s -b 0.0.0.0 -p 8888
/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/uniform_notifier-1.8.0/lib/uniform_notifier/growl.rb:16:in `rescue in rescue in setup_connection': You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp` (UniformNotifier::NotificationError)
# もしくは
/home/vagrant/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/uniform_notifier-1.8.0/lib/uniform_notifier/xmpp.rb:26:in `rescue in setup_connection': You must install the xmpp4r gem to use XMPP notification: `gem install xmpp4r` (UniformNotifier::NotificationError)
# もしくは
/var/www/html/pugiemonn.com/config/environments/development.rb:49:in `block (2 levels) in <top (required)>': undefined method `honeybadger=' for Bullet:Module (NoMethodError)
つまりruby-growl
やxmpp4r
、honeybadger
というgemがないから入れろとメッセージにかかれています。
development.rbから該当箇所を削除
設定に書いてあったgemなどrakeでエラーがでたものはとりあえず使用しないので削除しました。
development.rbから設定を削除
vi config/environments/development.rb
config.after_initialize do
Bullet.enable = true
Bullet.alert = true
Bullet.bullet_logger = true
Bullet.console = true
Bullet.rails_logger = true
Bullet.bugsnag = true
Bullet.airbrake = true
Bullet.add_footer = true
Bullet.stacktrace_includes = [ 'your_gem', 'your_middleware' ]
end
とりあえずエラーはでなくなりました。
ほかにも使用しない機能は削除しておくと良いですね(☝ ՞ਊ ՞)