Module: Controllers::DeviceDetection
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/concerns/controllers/device_detection.rb
Overview
Device detection utilities using the device_detector gem
Provides methods for detecting browser and device type from User-Agent.
Usage:
if is_ie?
render 'ie_warning'
end
device_detector.device_type # => 'desktop', 'mobile', etc.
Instance Method Summary collapse
-
#device_detector ⇒ Object
Returns a DeviceDetector instance for the current request Memoized to avoid repeated parsing.
-
#is_ie? ⇒ Boolean
Check if the browser is Internet Explorer Used for legacy browser warnings.
Instance Method Details
#device_detector ⇒ Object
Returns a DeviceDetector instance for the current request
Memoized to avoid repeated parsing
26 27 28 29 30 31 32 33 |
# File 'app/concerns/controllers/device_detection.rb', line 26 def device_detector return @device_detector if defined?(@device_detector) # Ensure all header values are strings to prevent nil gsub errors headers_hash = request.headers.respond_to?(:to_h) ? request.headers.to_h : {} safe_headers = headers_hash.transform_values { |v| v.to_s } @device_detector = DeviceDetector.new(request.user_agent, safe_headers) end |
#is_ie? ⇒ Boolean
Check if the browser is Internet Explorer
Used for legacy browser warnings
37 38 39 |
# File 'app/concerns/controllers/device_detection.rb', line 37 def is_ie? device_detector.name == 'Internet Explorer' end |