Last active
December 26, 2015 02:29
-
-
Save jspaper/7079146 to your computer and use it in GitHub Desktop.
把mobile的request一律只render page#home (layout是mobile.html),之後就統一由angular接管route。
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 :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 |
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
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