我有一个 Rails 应用程序,使用 AngularJS 进行客户端开发。我尝试加载位于“app/assets/javascripts/templates/”中的模板:
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: '/index.html',
controller: 'MainController'
}).
otherwise({
redirectTo: '/'
});
}]);
但我总是收到错误:“错误:[$compile:tpload] 无法加载模板:/index.html”。
我尝试将“templates”文件夹移出 javascripts - app/assets/templates 并通过将以下行添加到 config/application.rb 将其添加到我的资产管道加载中:config.assets.paths << Rails.root.join("app","assets","templates")
在使用模板的完整路径之前,我不断收到相同的错误消息:templateUrl: '/assets/index.html',
.
为什么第一种方法不够呢? Angular-rails-templates gem 不应该在 app/assets/javascripts/templates 中查找模板吗?
为什么我应该在 javascript 中使用资产的完整路径?
我的问题是sprockets
不兼容。版本 2.1.3 可以工作,所以我把它放在我的Gemfile
:
gem 'sprockets', '2.12.3'
我跑了bundle update sprockets
一切都是桃色的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)