Skip to content

Commit

Permalink
Correctly hook on Action Controller (#338)
Browse files Browse the repository at this point in the history
When an initializer load the `ActionController::Base` constant all the
on_load triggers for `:action_controller` are executed. This cause a lot of
load order issues.

Gems should always use `ActiveSupport.on_load` to extent behavior of the
Rails frameworks.

Also using `ActiveSupport.on_load(:action_controller)` we can make sure
that both `ActionController::Base` and `ActionController::Api` are extended.
  • Loading branch information
rafaelfranca authored and kattrali committed Jan 23, 2017
1 parent 9a32252 commit 514cd6a
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/bugsnag/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ class Railtie < Rails::Railtie
config = YAML.load_file(config_file) if File.exist?(config_file)
Bugsnag.configure(config[::Rails.env] ? config[::Rails.env] : config) if config

if defined?(::ActionController::Base)
ActiveSupport.on_load(:action_controller) do
require "bugsnag/rails/controller_methods"
::ActionController::Base.send(:include, Bugsnag::Rails::ControllerMethods)
end
if defined?(ActionController::API)
ActionController::API.send(:include, Bugsnag::Rails::ControllerMethods)
include Bugsnag::Rails::ControllerMethods
end
ActiveSupport.on_load(:active_record) do
require "bugsnag/rails/active_record_rescue"
Expand Down

0 comments on commit 514cd6a

Please sign in to comment.