2011-07-30 35 views
9

Man,WTH正在進行這項工作。你知道Rails 3.1中實際做了哪些事情?爲什麼= javascript_include_tag:默認不能在Rails 3.1的haml佈局中工作

<script src="/assets/defaults.js" type="text/javascript"></script> 

就像他們在ESPN上說的那樣,「來吧,夥計。」

我知道資產不再被視爲二等公民。但似乎他們甚至無法在這位候選人中獲得綠卡。在新的應用/ assets/javascripts/application.js中:

// This is a manifest file that'll be compiled into including all the files listed below. 
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically 
// be included in the compiled file accessible from http://example.com/assets/application.js 
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 
// the compiled file. 
// 
//= require jquery 
//= require jquery_ujs 
//= require_tree . 

Sooooo。我應該下載jQuery嗎?我該怎麼辦?因爲除了application.js之外,這個javascripts目錄中沒有任何內容。

加重。然而它是免費的,所以我怎麼抱怨?無論如何,這些問題似乎很基本,但我希望你能提供任何幫助。

回答

17

在Rails 3.1中,不再有像這樣的「默認值」,而是application.js文件中指定的是「默認值」。你會使用這條線包括本文件:

javascript_include_tag "application" 

jqueryjquery_ujs文件來與jquery-rails寶石這是在默認的Rails 3.1 Gemfile

在該文件中//= require行告訴你想要求在這種情況下將jquery.jsjquery-rails,其中//= require_tree .將需要在同一個目錄中的所有其他JavaScript文件作爲application.js,並將它們全部連接成中的文件鏈輪一個文件。

您可以閱讀更多關於the asset pipeline here

+2

謝謝RB。這讓我瘋狂。我想漂亮的腳手架還沒有趕上。我不能相信JS文件嵌入在寶石中。這對我來說似乎有點「神奇」。我無法弄清楚Sprockets如何知道如何看待那顆寶石,我不喜歡它。 – AKWF

+0

由於提供的鏈接已損壞,因此以下是有關資產管道的rails文檔的鏈接:http://guides.rubyonrails.org/asset_pipeline.html –

+0

謝謝@ t3__rry。我更新了鏈接。 –

相關問題