新手问题 Rails 中,如何判断是否是手机访问

string2020 · October 21, 2014 · Last by string2020 replied at October 21, 2014 · 2766 hits

有现成的 gem 可以用吗?

可以根据用户浏览器的 user-agent 去判断,这个库已经封装得很好了,可以直接通过 mobile? 去判断了。

https://github.com/josh/useragent/blob/master/lib/user_agent/browsers/base.rb#L55-L66

ruby-china 的源码中如是写:

要是 rails 有自带的方法就好了。

You need to Sign in before reply, if you don't have an account, please Sign up first.