angular-rails-templates:找不到模板 [英] angular-rails-templates: templates are not found

查看:30
本文介绍了angular-rails-templates:找不到模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 rails 应用程序,使用 angularjs 进行客户端开发.我尝试加载位于`app/assets/javascripts/templates/' 中的模板:

I have a rails application, using angularjs for the client side development. I try to load a template located in `app/assets/javascripts/templates/':

myApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
      when('/', {
        templateUrl: '/index.html',
        controller: 'MainController'
      }).
      otherwise({
        redirectTo: '/'
      });
  }]);

但我总是收到错误:错误:[$compile:tpload] 无法加载模板:/index.html".

but I always get a error: "Error: [$compile:tpload] Failed to load template: /index.html".

我尝试将templates"文件夹移出 javascripts - app/assets/templates 并将其添加到我的资产管道加载中,方法是将以下行添加到 config/application.rb:config.assets.路径<

I tried to move the "templates" folder out of the javascripts - app/assets/templates and to add it to my assets pipeline load by adding the following line to config/application.rb: config.assets.paths << Rails.root.join("app","assets","templates")

在使用模板的完整路径之前,我一直收到相同的错误消息:templateUrl: '/assets/index.html',.

I keep getting the same error message until I use the full path to the template: templateUrl: '/assets/index.html',.

  1. 为什么第一种方法还不够?angular-rails-templates gem 不应该在 app/assets/javascripts/templates 中查找模板?

  1. Why the first method is not enough? the angular-rails-templates gem shouldn't look for templates in app/assets/javascripts/templates?

为什么要在我的 javascript 中使用资产的完整路径?

Why should I use the full path to an assets inside my javascript?

推荐答案

我的问题是 sprockets 不兼容.2.1.3 版可以工作,所以我把它放在我的 Gemfile 中:

My problem has been a sprockets incompatibility. Version 2.1.3 works though so I put this in my Gemfile:

gem 'sprockets', '2.12.3'

我运行了bundle update sprockets,一切都很好.

And I ran bundle update sprockets and it's all peachy.

这篇关于angular-rails-templates:找不到模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆