Precompile rails AngularJS assets

I am trying to compile my Rails app assets using RAILS_ENV=production bundle exec rake assets:precompile, but this doesn't compile my AngularJS assets, so my console report this:

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

My AngularJS assets are under "/assets/app/", so I tried to compile the angular folders by adding following into my production.rb but still not working.

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

I can find the compiled index file under this path:

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

Any idea?

UPDATE

Also tried config.serve_static_assets = false in production, but it cause more missing assets errors

Thanks


I've worked through this in my app by using constants to get the path structure right.

my angular app is journey (yours would obviously be different)

so I declare the angular app as a module

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

Then I have a file called constants.js.erb where I declare my templates

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

Finally in my services I use the constants declared as the template 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'
      })
     }
   ])

This way I don't have to worry about where the files are or how rails is organising the routing.

Hope this helps

链接地址: http://www.djcxy.com/p/79996.html

上一篇: Heroku资产预编译在i18n上失败

下一篇: 预编译轨道AngularJS资产