RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: ptarud
Site: www.toeska.cl/~ptarud
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.
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.