Skip to content

Instantly share code, notes, and snippets.

@jspaper
Last active December 26, 2015 02:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jspaper/7079146 to your computer and use it in GitHub Desktop.
Save jspaper/7079146 to your computer and use it in GitHub Desktop.
把mobile的request一律只render page#home (layout是mobile.html),之後就統一由angular接管route。
class ApplicationController < ActionController::Base
before_filter :mobile_view_redirect
layout :which_layout
def mobile_device?
request.user_agent =~ /Mobile|webOS|Android/
end
helper_method :mobile_device?
def which_layout
mobile_device? ? 'mobile' : 'application'
end
def mobile_view_redirect
if mobile_device? and request.format.html? and request.env['PATH_INFO'] != '/'
logger.info "Mobile version render /"
render :layout => which_layout, :template => "pages/home"
end
end
end
angular.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
controller: 'PagesCtrl',
templateUrl: '/partials/pages/home.html'})
.when('/pictures/:id', {
controller: 'PictureCtrl',
templateUrl: '/partials/pictures/show.html'})
.otherwise({ redirectTo: '/' });
$locationProvider.html5Mode(true);
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment