23

在我的 application.js 文件中,我有:

//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require_tree .
//
//= require .//community_app
//
//= require_tree ../templates/
//= require_tree .//models
//= require_tree .//collections
//= require_tree .//views
//= require_tree .//routers

但生成的 html 不遵守此顺序:

<head>
  <title>CommunityApp</title>
  <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/communities.css?body=1" media="all" rel="stylesheet" type="text/css" />
<link href="/assets/home.css?body=1" media="all" rel="stylesheet" type="text/css" />
  <script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/underscore.js?body=1" type="text/javascript"></script>
<script src="/assets/backbone.js?body=1" type="text/javascript"></script>
<script src="/assets/collections/communities.js?body=1" type="text/javascript"></script>
<script src="/assets/community_app.js?body=1" type="text/javascript"></script>
<script src="/assets/home.js?body=1" type="text/javascript"></script>
<script src="/assets/models/community.js?body=1" type="text/javascript"></script>
<script src="/assets/application.js?body=1" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="ktrLMDYSJaU/mmgmzfpxDfMin7OCXga4K5gVIJZHJUI=" name="csrf-token" />
</head>
<body>

集合是在模型之前加载的,这在前端给我带来了错误。我怎样才能使它以特定方式加载js文件?谢谢

4

1 回答 1

35

你还有一个

//= require_tree .

更高的地方,它正在加载所有内容,显然是按字母顺序排列的。删除它(显然确保其他地方都需要所有东西),你应该没问题。您可能可以将其作为 application.js 的最后一行,但是当两个语句最终需要相同的文件时,我不记得指定的行为

于 2012-07-01T22:06:03.070 回答