2012-07-01 34 views
20

Trong file application.js tôi, tôi có:Rails chỉ định thứ tự tải của tệp javascript?

//= 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 

nhưng html tạo ra không tuân theo thứ tự này:

<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> 

Các bộ sưu tập được nạp trước khi mô hình đó mang lại cho tôi lỗi ở mặt trước -kết thúc. Làm thế nào tôi có thể làm cho nó để nó tải một cách cụ thể các tập tin js? nhờ

Trả lời

32

Bạn vẫn đã có một

//= require_tree . 

cao lên, mà đang tải tất cả mọi thứ, rõ ràng theo thứ tự chữ cái. Loại bỏ điều đó (rõ ràng là đảm bảo rằng mọi thứ được yêu cầu ở nơi khác) và bạn sẽ ổn. Bạn có thể làm cho dòng cuối cùng của application.js của mình nhưng tôi không nhớ hành vi được chỉ định khi hai câu lệnh kết thúc yêu cầu cùng một tệp

+2

Cảm ơn bạn đã nhập. Có cách nào tôi có thể làm cho require_tree không tải trong bảng chữ cái? Cách thích hợp để làm điều này là gì? – 0xSina

+1

@ 0xSina: Cách thích hợp để chỉ định một thứ tự cụ thể là, tốt, chỉ định thứ tự bằng tay như bạn (gần như) đang làm. –

+1

Tôi sẽ xóa 'require_tree .' và yêu cầu mọi thứ theo thứ tự mong muốn (có thể sử dụng require_tree trong thư mục con) –

Các vấn đề liên quan