【问题标题】:Precompile rails AngularJS assets预编译 Rails AngularJS 资产
【发布时间】:2013-09-27 09:50:06
【问题描述】:

我正在尝试使用 RAILS_ENV=production bundle exec rake assets:precompile 编译我的 Rails 应用程序资产,但这不会编译我的 AngularJS 资产,因此我的控制台会报告:

 ActionController::RoutingError (No route matches [GET] "/assets/app/views/products/index.html"):

我的 AngularJS 资产位于“/assets/app/”下,因此我尝试通过在 production.rb 中添加以下内容来编译 angular 文件夹,但仍然无法正常工作。

 config.assets.precompile += %w(app/* bootstrap/* datatable/* ....

我可以在这个路径下找到编译好的索引文件:

 public/assets/app/views/products/index-2429bd0f8fc0762dcc075e51f0306c5b.html

有什么想法吗?

更新

还在生产中尝试过 config.serve_static_assets = false,但它会导致更多的资产丢失错误

谢谢

【问题讨论】:

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


    【解决方案1】:

    我已经在我的应用程序中通过使用常量来获得正确的路径结构来解决这个问题。

    我的 Angular 应用是旅程(你的显然会有所不同)

    所以我将 Angular 应用程序声明为一个模块

    this.journey = angular.module('journey', [
        'ngResource',
        'ngRoute'
      ]);
    

    然后我有一个名为 constants.js.erb 的文件,我在其中声明了我的模板

    journey.constant('INDEX_TEMPLATE', '<%= asset_path('journeys/journey_index.html')%>');
    journey.constant('EDIT_JOURNEY_TEMPLATE', '<%= asset_path('journeys/journey_edit.html') %>');
    

    最后,在我的服务中,我使用了声明为模板 url 的常量

    journey.config([
        '$routeProvider',
        '$locationProvider',
        'INDEX_TEMPLATE',
        'EDIT_JOURNEY_TEMPLATE',
        function ($routeProvider, $locationProvider, INDEX_TEMPLATE, EDIT_JOURNEY_TEMPLATE) {
          $locationProvider.html5Mode(false);
          return $routeProvider.when('/', {
            templateUrl: INDEX_TEMPLATE,
            controller: 'JourneyIndexController'
          })
         }
       ])
    

    这样我就不必担心文件在哪里或 rails 如何组织路由。

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      相关资源
      最近更新 更多