Skip to content

Instantly share code, notes, and snippets.

@ptb
Created April 9, 2014 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptb/10278501 to your computer and use it in GitHub Desktop.
Save ptb/10278501 to your computer and use it in GitHub Desktop.
Rails 4.1 Action Pack Variants for iOS and Android
class ApplicationController < ActionController::Base
before_action :detect_device_type
private
def detect_device_type
case request.user_agent
when /ip(hone|od)/i
request.variant = :ipod
when /android.+mobile/i
request.variant = :droid
when /ipad/i
request.variant = :ipad
when /android|silk/i
request.variant = :tablet
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment