Add BrowserDetection
model concern (#29513)
This commit is contained in:
parent
d7ab5655ef
commit
62e266fbd6
3 changed files with 31 additions and 29 deletions
27
app/models/concerns/browser_detection.rb
Normal file
27
app/models/concerns/browser_detection.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module BrowserDetection
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
before_save :assign_user_agent
|
||||
end
|
||||
|
||||
def detection
|
||||
@detection ||= Browser.new(user_agent)
|
||||
end
|
||||
|
||||
def browser
|
||||
detection.id
|
||||
end
|
||||
|
||||
def platform
|
||||
detection.platform.id
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assign_user_agent
|
||||
self.user_agent ||= ''
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue