在 Rails 3 中检测用户操作系统的最简单方法是什么? [英] What's the easiest way to detect the user's operating system in Rails 3?

查看:33
本文介绍了在 Rails 3 中检测用户操作系统的最简单方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的 Rails 应用程序,主要是脚手架.我想检测用户是使用 Android 还是 iPhone 来访问我的应用程序.最简单的方法是什么?

Simple Rails app, mostly scaffolding. I want to detect whether the user is using Android or iPhone to access my app. What's the easiest way to do that?

推荐答案

if request.env['HTTP_USER_AGENT'].downcase.match(/android|iphone/)
  puts "yup, its mobile"
end

这篇关于在 Rails 3 中检测用户操作系统的最简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆