Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Paulo Tarud C's Profile

GitHub User: ptarud

Site: www.toeska.cl/~ptarud

Comments by Paulo Tarud C

Avatar

Hi everyone:

If you want to detect if mobile or not, an easier way to do that is define this method in your controller:
Thereafter, you have to call this method with :

before_filter :check_mobile

def check_mobile
if request.user_agent =~ /Android/i
session[:mobile] = true
elsif request.user_agent =~ /BlackBerry/i
session[:mobile] = true
elsif request.user_agent =~ /iPhone|iPad|iPod/i
session[:mobile] = true
elsif request.user_agent =~ /IEMobile/i
session[:mobile] = true
else
session[:mobile] = false
end
end

thereafter your session[:mobile] will have true if you are in mobile and false if you not.

I hope its helpful for you.