[英]Precompile rails AngularJS assets
我正在嘗試使用RAILS_ENV = production bundle exec rake asset:precompile編譯我的Rails應用程序資產,但這不能編譯AngularJS資產,因此我的控制台報告如下:
ActionController::RoutingError (No route matches [GET] "/assets/app/views/products/index.html"):
我的AngularJS資產位於“ / assets / app /”下,因此我嘗試通過在我的production.rb中添加以下內容來編譯有角度的文件夾,但仍無法正常工作。
config.assets.precompile += %w(app/* bootstrap/* datatable/* ....
我可以在以下路徑下找到編譯的索引文件:
public/assets/app/views/products/index-2429bd0f8fc0762dcc075e51f0306c5b.html
任何想法?
UPDATE
還嘗試在生產中使用config.serve_static_assets = false,但這會導致更多資產丟失錯誤
謝謝
我已經在我的應用程序中通過使用常量來正確處理路徑結構來解決此問題。
我的棱角分明的應用程序是旅程(您的顯然會有所不同)
所以我將angular app聲明為模塊
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如何組織路由。
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.