Module: Ahoy::Model
- Defined in:
- lib/ahoy/model.rb
Instance Method Summary collapse
Instance Method Details
#visitable(name = :visit, **options) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/ahoy/model.rb', line 3 def visitable(name = :visit, **) class_eval do = .dup [:optional] = true if Rails::VERSION::MAJOR >= 5 belongs_to(name, class_name: "Ahoy::Visit", **) before_create :set_ahoy_visit end class_eval %{ def set_ahoy_visit self.#{name} ||= RequestStore.store[:ahoy].try(:visit_or_create) end } end |