Help us understand the problem. What is going on with this article?

Railsのデバイス判定にbrowser

More than 3 years have passed since last update.

ブラウザ判定(IEやFirefox、Chromeとか)やデバイスの判定(PCかスマホか)したい時には大体UserAgentつかうでしょうが、最近は複雑化しているから対応が簡単でないですね。
RailsはこれをやるためにbrowserというGemがあります。超便利。
https://github.com/fnando/browser

しかし、ここのReadme通りにインストールすると依存関係の問題か0.9.1(2016年8月現在)しか入らないです。
ということで自分なりの使い方ですが、Gemfileに

Gemfile
# browser detection
gem 'browser', '~> 2.2.0'

と書きます。

あとはいつものbundle install

Viewの箇所には
if browser.device.mobile?

とヘルパーbrowserを入れるのでOKです。他にもbrowser.ie?(6) とかbrowser.platform.android?(4.2)とかbrowser.device.xbox?なんて出来る。

便利ですな。

hardreggaecafe
A freelance engineer.
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした