Rails way to detect mobile device?

You can do it that way by defining a function like below:

def mobile_device?
  if session[:mobile_param]
    session[:mobile_param] == "1"
  else
    request.user_agent =~ /Mobile|webOS/
  end
end

Or you can use gems to detect mobile devices like

  • https://github.com/tscolari/mobylette
  • https://github.com/shenoudab/active_device

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)