【问题标题】:AngularJS templates in Rails production not availableRails 生产中的 AngularJS 模板不可用
【发布时间】:2019-01-17 08:13:57
【问题描述】:

我正在使用 Rails(4.2) + AngularJS。这里的模板分为两类,一类是直接从 config.js.erb 引用的

 .when('/users', {
        templateUrl: '<%= asset_path("users.html") %>',
        controller: UserListCtrl
      })

模板在生产中得到正确处理,并加载了用户模板的预编译版本。

从模板内部调用的其他人像

<pane ng-if="$index == 0" ng-form name="chm_standard" pane-form="details.form.routing.call_handling_mode.chm_standard" heading="{{global.chm_types[0].Description}}">
   <div ng-include="'/assets/chm.html'"></div>
</pane>

开发模式下的 chm.html.erb 从 app/assets/javascripts/templates/en/chm.html 获取。 这会在生产中产生错误,“找不到模板”,因为我有

chm-fer342xx.html 在 public/assets/javascripts/templates 中

如何处理,将所有模板移动到公共/文件夹唯一选项可用吗?

【问题讨论】:

标签: ruby-on-rails angularjs ruby templates asset-pipeline


【解决方案1】:

当使用ng-include 时,角度只会从受信任的资源加载。

浏览器可能由于 CORS 限制而被阻止。

【讨论】:

  • 没有加载模板,浏览器控制台给出错误“找不到模板”,因为该文件在路径中不可用。
  • @Bijendra 你为什么提到 /assets?将完整路径放在 public/assets/JavaScripts/templates.
  • 相同的路径在 dev 和 prod 中不起作用,因为它的获取方式不同
猜你喜欢
  • 2014-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-21
  • 2011-03-19
  • 1970-01-01
相关资源
最近更新 更多