Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created March 27, 2012 14:28

Revisions

  1. kinopyo created this gist Mar 27, 2012.
    12 changes: 12 additions & 0 deletions application_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # from https://github.com/ruby-china/ruby-china/blob/master/app/helpers/application_helper.rb

    MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
    'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
    'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
    'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
    'webos|amoi|novarra|cdm|alcatel|pocket|iphone|mobileexplorer|mobile'
    def mobile?
    agent_str = request.user_agent.to_s.downcase
    return false if agent_str =~ /ipad/
    agent_str =~ Regexp.new(MOBILE_USER_AGENTS)
    end