Also include Ahoy::Controller in ActionController::API subclasses (#248)

Ernest Surudo committed Jan 27, 2017
commit 376d4cc0ffb68d28cc472960168384c8136a42b2
Showing 2 changed files with 5 additions and 2 deletions
ahoy.rb b/lib/ahoy.rb +1 -0
@@ @@ -118,6 +118,7 @@ end
if defined?(Rails)
ActiveSupport.on_load(:action_controller) do
ActionController::Base.send :include, Ahoy::Controller
+ ActionController::API.send :include, Ahoy::Controller if defined?(ActionController::API)
end
ActiveSupport.on_load(:active_record) do
ahoy/controller.rb b/lib/ahoy/controller.rb +4 -2
@@ @@ -3,8 +3,10 @@ require "request_store"
module Ahoy
module Controller
def self.included(base)
- base.helper_method :current_visit
- base.helper_method :ahoy
+ if base.respond_to?(:helper_method)
+ base.helper_method :current_visit
+ base.helper_method :ahoy
+ end
if base.respond_to?(:before_action)
base.before_action :set_ahoy_cookies, unless: -> { Ahoy.api_only }
base.before_action :track_ahoy_visit, unless: -> { Ahoy.api_only }