Created
September 4, 2014 02:43
-
-
Save exegeteio/58d2a2829b4cee98c81e to your computer and use it in GitHub Desktop.
ApplicatController
This file contains 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 | |
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