Support Rails 4.2 for visitable (#342)

Christian Billen committed Mar 21, 2018
commit a70fe2ed3065b929ee886d85e8619ea355ca938a
Showing 1 changed file with 3 additions and 1 deletions
ahoy/model.rb b/lib/ahoy/model.rb +3 -1
@@ @@ -2,7 +2,9 @@ module Ahoy
module Model
def visitable(name = :visit, **options)
class_eval do
- belongs_to(name, optional: true, class_name: "Ahoy::Visit", **options)
+ safe_options = options.dup
+ safe_options[:optional] = true if Rails::VERSION::MAJOR >= 5
+ belongs_to(name, class_name: "Ahoy::Visit", **safe_options)
before_create :set_ahoy_visit
end
class_eval %{