2

当我第一次将我的应用程序转移到生产环境时,我发现了一些问题。我发现我应该在生产中使用预编译的资产,所以我尝试编译它们,但得到了这个错误:

rake aborted!
/var/www/tracker/app/assets/templates/snippets/comment.html.erb has already been required
  (in /var/www/tracker/app/assets/javascripts/angularjs/routes.coffee.erb)

这里最令人困惑的是, routes.coffee.erbcomment.html.erb中根本没有提到该文件,它只包含一些angularjs的路由:

angular.module('app', ['ui', 'app.services', 'app.directives', 'app.filters', 'ngCookies', 'ngSanitize', 'mwTable'])
  .config ['$routeProvider', ($routeProvider) ->

    $routeProvider.when '/',
      templateUrl: '<%= asset_path('announces/list.html') %>'
      controller: AnnouncesListCtrl

    $routeProvider.when '/announce/:fid',
      templateUrl: '<%= asset_path('announces/view.html') %>'
      controller: AnnouncesViewCtrl

    $routeProvider.when '/announce/:fid/edit',
      templateUrl: '<%= asset_path('announces/edit.html') %>'
      controller: AnnouncesEditCtrl

    $routeProvider.when '/registration',
      templateUrl: '<%= asset_path('users/edit.html') %>'
      controller: UsersEditCtrl

    $routeProvider.when '/registration_successful',
      templateUrl: '<%= asset_path('users/registration_successful.html') %>'
      controller: UsersEditCtrl

    $routeProvider.when '/users',
      templateUrl: '<%= asset_path('users/list.html') %>'
      controller: UsersListCtrl

    $routeProvider.otherwise({redirectTo: '/'})

  ]

我唯一能想到的就是我用过<%= asset_path('announces/view.html') %>的,它又包含<%= asset_path('snippets/comment.html')%>. 如果这导致了问题,那么想到的唯一解决方案就是不使用asset_path. 但是这样做可以吗?

完整的错误信息在这里:https ://gist.github.com/SET/5167092 。尽管它的大小,它是 99% 无用的。

另外,由于我是 Rails 新手(来自 PHP),我不明白为什么已经需要某些东西如此重要?您需要它几次,但只加载一次;为什么这会导致问题?

更新: 我解决了将 <%= asset_path(template) %>` 替换为 '/assets/template' 的问题,但这不是一个丑陋的解决方案吗?

4

0 回答 0