Me he encontrado en la tesitura de tener que detectar si un visitante usa un navegador desde un dispositivo móvil y entonces enviarlo a la versión móvil de L-exp.
Para ello me he basado en una página en donde están todos los UserAgent que identifican todos los navegadores. La implementación en Ruby on Rails ha sido muy sencilla.
En el Application controller:
def check_mobile
agent = request.user_agent
if is_mobile(agent) then
redirect_to(’/mobile/’) #new mobile address
end
end
def is_mobile(agent)
# based on http://www.zytrax.com/tech/web/mobile_ids.html
case agent
when /Nokia/, /AvantGo/, /DoCoMo/, /Vodafone/, /PalmOS/, /Windows CE/, /Minimo/, /Plucker/, /Palmsource/, /NetFront/, /PIE/, /iPhone/, /BlackBerry/, /MOT-/, /Nokia/, /Symbian/, /O2/, /Mini/, /Blazer/, /MobileExplorer/, /RegKing/, /EPOC/, /SAGEM/, /SCH-/, /SGH/, /SIE/, /SonyEricsson/
return true
else
return false
end
end
En el controlador que quiero redireccionar:
class TheController < ApplicationController…. before_filter :check_mobile
…..
end
Lo acabo de instalar y parece que funciona.

Post a Comment