class Rails_Agent_Detect
Public Class Methods
is_mobile()
click to toggle source
# File lib/rails_agent_detect.rb, line 3 def self.is_mobile docomo = "docomo" softbank = "softbank" au = "au" iphone = "iphone" ipad = "ipad" android = "anroid" blackberry = "blackberry" blackberry5 = "blackberry5" windowsphone = "windowsphone" windowsphone7 = "windowsphone7" windowsphone8 = "windowsphone8" motorola = "motorola" symbian = "symbian" mobile = "mobile" lg = "lg" pc = "pc" default = "default" # url = "http://#{request.host+request.fullpath}" # url1 = "http://#{request.host}:#{request.port}#{request.fullpath}" # link = url1.gsub("#{request.host}:#{request.port}","#{request.host}:#{request.port}/m") # check_url = "http://#{request.host}:#{request.port}\/m" user_agent = request.env['HTTP_USER_AGENT'].downcase if request.env['HTTP_USER_AGENT'].present? if (user_agent.to_s.match(/iphone/) || user_agent.to_s.match(/ipad/) || user_agent.to_s.match(/android/) || user_agent.to_s.match(/blackberry/) || user_agent.to_s.match(/blackberry5/) || user_agent.to_s.match(/windowsphone/) || user_agent.to_s.match(/windowsphone7/) || user_agent.to_s.match(/windowsphone8/) || user_agent.to_s.match(/motorola/) || user_agent.to_s.match(/symbian/)) return true # if (user_agent.to_s.match(/ipad/)) # @@is_tablet = true # elsif (user_agent.to_s.match(/android/)) # if (user_agent.to_s.match(/mobile/)) # @@is_tablet = false # else # @@is_tablet = true # end # end #redirect_to link unless url1.to_s.match(check_url.to_s) else return false end end