Skip to content

Instantly share code, notes, and snippets.

@somenugget
Created May 14, 2021 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somenugget/706909245a3de4276396263e4e70b3b8 to your computer and use it in GitHub Desktop.
Save somenugget/706909245a3de4276396263e4e70b3b8 to your computer and use it in GitHub Desktop.
module Concerns
module BrowserCheck
extend ActiveSupport::Concern
NOT_SUPPORTED_VERSIONS = {
ie: 11,
edge: 19,
ios: 12,
android: 6
}.freeze
included do
before_action :check_browser
end
private
def check_browser
byebug
if browser_not_supported?
redirect_to update_browser_path
elsif os_not_supported?
redirect_to update_os_path
end
end
def browser_not_supported?
[
browser.ie?(not_supported_versions_for(:ie)),
browser.edge?(not_supported_versions_for(:edge))
].any?
end
def os_not_supported?
[
browser.platform.ios?(not_supported_versions_for(:ios)),
browser.platform.android?(not_supported_versions_for(:android))
].any?
end
def not_supported_versions_for(key)
next_version = NOT_SUPPORTED_VERSIONS[key] + 1
"< #{next_version}"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment