简体   繁体   English

Angular JS与Ruby on Rails路由问题

[英]Angular JS with Ruby on Rails Routing Issues

I'm trying to use Angular with Ruby on Rails. 我正在尝试将Angular与Ruby on Rails一起使用。 I'm wondering what the best way to do this would be. 我想知道这样做的最佳方法是什么。 Currently I have a rails application that authenticates using Ruby. 目前,我有一个使用Ruby进行身份验证的Rails应用程序。 I however want the homepage of the site to be using Angular. 但是,我希望网站的主页使用Angular。 How does this work with the controller and routes in angular? 这如何与控制器一起工作并成角度地布线? I want to use a CDN for using Angular (no gems for this). 我想使用CDN来使用Angular(为此没有宝石)。

This is what my angular routes look like: 这是我的角度路线:

var shopApp = angular.module('shopApp', ['ngRoute',        'shopControllers']);

shopApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
  when('/shop', {
    templateUrl: '../templates/shop.html',
    controller: 'ItemsController'
  }).
  when('/details/:itemId', {
    templateUrl: '../templates/details.html',
    controller: 'DetailsController'
  })
}]);

This is what my controllers look like: 这是我的控制器的外观:

var shopControllers = angular.module('shopControllers', []);
shopControllers.controller('ItemsController', ['$scope','$http', function ($scope, $http, $routeParams) {

}]);

shopControllers.controller('DetailsController', ['$scope','$http',  '$routeParams', '$location', function ($scope, $http, $routeParams,            $location) {

}]);

My question is: how is this supposed to work with the Ruby on Rails routes? 我的问题是:Ruby on Rails路线应该如何使用? if I do '/#/shop' shouldn't I be able to see the angular template view? 如果我执行“ /#/ shop”,是否应该看不到角度模板视图?

Thanks in advance 提前致谢

Create a route for the angular app in ruby on rails. 为Rails中的ruby创建角度应用程序的路线。 This route will be the only route that ruby identifies with, but angular can use its own routing for pages within the single app. 这条路线将是ruby识别的唯一路线,但是angular可以在单个应用程序中针对页面使用其自己的路线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM