Last active
August 29, 2015 14:06
-
-
Save pachisaez/ec51afc90bdca9be10fb to your computer and use it in GitHub Desktop.
Detecting the device that is accessing the app so you can adapt views and behavior to it, via the Mobvious plugin (https://github.com/jistr/mobvious).
Rendering .mobile files only if the device is a smartphone.
session[:device] will contain "desktop", "tablet" or "mobile".
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationController < ActionController::Base | |
before_filter :prepare_for_mobile | |
# we'll render *.mobile.erb files instead of *.html.erb files when the | |
# device session variable is set to "mobile" | |
def prepare_for_mobile | |
session[:device] = params[:device] if params[:device] | |
request.format = :mobile if mobile_device? | |
end | |
def mobile_device? | |
unless session[:device] | |
strategy = Mobvious::Strategies::MobileESP.new(:mobile_tablet_desktop) | |
session[:device] = strategy.get_device_type(request).to_s | |
end | |
session[:device] == "mobile" | |
end | |
helper_method :mobile_device? | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment