Skip to content

Instantly share code, notes, and snippets.

@exegeteio
Created September 4, 2014 02:43
Show Gist options
  • Save exegeteio/58d2a2829b4cee98c81e to your computer and use it in GitHub Desktop.
Save exegeteio/58d2a2829b4cee98c81e to your computer and use it in GitHub Desktop.
ApplicatController
class ApplicationController < ActionController::Base
before_filter :prepare_for_mobile
private
## Is this a mobile device?
def mobile_device?
if session[:mobile_param]
session[:mobile_param] == "1"
else
request.user_agent =~ /Mobile|webOS/
end
end
helper_method :mobile_device?
## Change the format if it is mobile.
def prepare_for_mobile
session[:mobile_param] = params[:mobile] if params[:mobile]
prepend_view_path Rails.root + 'app' + 'views' + 'mobile' if mobile_device?
# request.format = :mobile if mobile_device?
end
def which_layout
mobile_device? ? 'mobile' : 'application'
end
layout :which_layout
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment