2012-11-11 144 views
1

好吧,我的資產管道突然開始在我的開發機器上動作了。以前工作的JS函數現在拋出「不是函數」錯誤..我知道我必須做錯了什麼。一分鐘前,數據表jquery函數正在工作,然後它拋出一個錯誤,然後它正在工作,現在它不工作或拋出一個錯誤。資產管道代理

這裏是我的application.js

//= require jquery 
//= require jquery-ui 
//= require jquery_ujs 
//= require_self 
//= require_tree . 
//= require dataTables/jquery.dataTables 
//= require dataTables/jquery.dataTables.bootstrap 
//= require bootstrap 
//= require bootstrap-tooltip 
//= require bootstrap-popover 
//= require bootstrap-tab 
//= require bootstrap-modal 
//= require bootstrap-alert 
//= require bootstrap-dropdown 
//= require jquery.ui.addresspicker 
//= require raty 
//= require jquery.alphanumeric 
//= require jquery.formrestrict 
//= require select2 
//= require chosen/chosen.jquery 
//= require highcharts 
//= require jquery.lazyload 

下面是我的一些佈局的頭信息:

<%= stylesheet_link_tag "application", media: "all" %> 
    <%= yield(:scripthead) %> 
    <%= javascript_include_tag "application" %> 
    <%= csrf_meta_tags %>  
    <%= yield(:head) %> 

上面,我是用產量爲他們只是從谷歌加載在線腳本在一些頁面上需要,如果包含在應用程序佈局中,通常會降低網站的速度。我嘗試刪除收益率,但是,即使在清除瀏覽器緩存並運行rake資產之後,仍然有問題:clean(僅僅是爲了安全起見)。

這裏的CSS和元標記之間顯示的內容(的頁面與產量scripthead沒什麼):

<script src="/assets/jquery.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery-ui.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> 
<script src="/assets/application.js?body=1" type="text/javascript"></script> 
<script src="/assets/aidmodels.js?body=1" type="text/javascript"></script> 
<script src="/assets/audio.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-alert.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-dropdown.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-modal.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-popover.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-tab.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-tooltip.js?body=1" type="text/javascript"></script> 
<script src="/assets/branches.js?body=1" type="text/javascript"></script> 
<script src="/assets/charts.js?body=1" type="text/javascript"></script> 
<script src="/assets/chosen/backup_chosen.jquery.js?body=1" type="text/javascript"></script> 
<script src="/assets/chosen/chosen.jquery.js?body=1" type="text/javascript"></script> 
<script src="/assets/consumers.js?body=1" type="text/javascript"></script> 
<script src="/assets/dispensers.js?body=1" type="text/javascript"></script> 
<script src="/assets/favorites.js?body=1" type="text/javascript"></script> 
<script src="/assets/features.js?body=1" type="text/javascript"></script> 
<script src="/assets/generic_styles.js?body=1" type="text/javascript"></script> 
<script src="/assets/gmaps4rails/gmaps4rails.base.js?body=1" type="text/javascript"></script> 
<script src="/assets/gmaps4rails/gmaps4rails.bing.js?body=1" type="text/javascript"></script> 
<script src="/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" type="text/javascript"></script> 
<script src="/assets/gmaps4rails/gmaps4rails.mapquest.js?body=1" type="text/javascript"></script> 
<script src="/assets/gmaps4rails/gmaps4rails.openlayers.js?body=1" type="text/javascript"></script> 
<script src="/assets/highcharts.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery-ui-1.8.18.custom.min.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery.alphanumeric.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery.formrestrict.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery.lazyload.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery.ui.addresspicker.js?body=1" type="text/javascript"></script> 
<script src="/assets/likes.js?body=1" type="text/javascript"></script> 
<script src="/assets/messages.js?body=1" type="text/javascript"></script> 
<script src="/assets/overalls.js?body=1" type="text/javascript"></script> 
<script src="/assets/pages.js?body=1" type="text/javascript"></script> 
<script src="/assets/questions.js?body=1" type="text/javascript"></script> 
<script src="/assets/raty.js?body=1" type="text/javascript"></script> 
<script src="/assets/reviews.js?body=1" type="text/javascript"></script> 
<script src="/assets/sessions.js?body=1" type="text/javascript"></script> 
<script src="/assets/styles.js?body=1" type="text/javascript"></script> 
<script src="/assets/tickets.js?body=1" type="text/javascript"></script> 
<script src="/assets/universities.js?body=1" type="text/javascript"></script> 
<script src="/assets/users.js?body=1" type="text/javascript"></script> 
<script src="/assets/dataTables/jquery.dataTables.js?body=1" type="text/javascript"></script> 
<script src="/assets/dataTables/jquery.dataTables.bootstrap.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-transition.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-affix.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-button.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-carousel.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-collapse.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-scrollspy.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap-typeahead.js?body=1" type="text/javascript"></script> 
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script> 
<script src="/assets/select2.js?body=1" type="text/javascript"></script> 

從application.rb中:

config.assets.initialize_on_precompile = false 
# Enable the asset pipeline 
config.assets.enabled = true 
config.action_controller.assets_dir = "#{File.dirname(File.dirname(__FILE__))}/public" 

# Version of your assets, change this if you want to expire all your assets 
config.assets.version = '1.0' 

對不起,我米不知道還有什麼可以幫助這個難題,但任何建議,將不勝感激。在開始嘗試上傳到heroku之前,我沒有遇到任何問題,現在一切都已經過時了。

編輯:

在此刻的控制檯我看到

Uncaught TypeError: Cannot read property 'Constructor' of undefined bootstrap-popover.js:33 
Uncaught ReferenceError: google is not defined jquery.ui.addresspicker.js:25 
Uncaught TypeError: Object [object Object] has no method 'popover' overall:476 

編輯2:

由於一個評論下面我能想出解決辦法。我不得不重新洗牌的application.js包括更有意義:

//= require jquery 
//= require jquery-ui 
//= require jquery_ujs 
//= require bootstrap 
//= require bootstrap-tooltip 
//= require bootstrap-popover 
//= require bootstrap-tab 
//= require bootstrap-modal 
//= require bootstrap-alert 
//= require bootstrap-dropdown 
//= require dataTables/jquery.dataTables 
//= require dataTables/jquery.dataTables.bootstrap 
//= require jquery.ui.addresspicker 
//= require raty 
//= require jquery.alphanumeric 
//= require jquery.formrestrict 
//= require select2 
//= require chosen/chosen.jquery 
//= require highcharts 
//= require jquery.lazyload 
//= require_self 
//= require_tree . 

OMG,這是推動我香蕉..不,它仍然是行不通的。最後一次編輯讓所有的東西都正常工作,但後來我運行了rake資源:再次預編譯並推送到了heroku中。它再次無法在Heroku上工作了,信不信由你,當我回到我的本地主機版本時,它已被破壞再次,並且現在拋出不同的錯誤,並且不再加載數據表!

Uncaught ReferenceError: google is not defined jquery.ui.addresspicker.js:25 
Uncaught ReferenceError: google is not defined application.js:26 
Uncaught TypeError: Object [object Object] has no method 'lazyload' overall:496 

回答

3

你確定你沒有忘記JS中的某個分號嗎?資產管道沒有做任何代碼清潔...

以在瀏覽器的JS控制檯看一下其中的錯誤吐痰......

編輯:好吧,我想看看這是怎麼回事。嘗試在最後取出require_tree並手動加載任何其他未明確聲明的JS文件。結果發生的是require_tree覆蓋了以前需要明確列出的所有要求,並最終按字母順序加載它們。

另外,我不知道你用什麼創業寶石。(或者如果你甚至使用一個),但也嘗試使用twitter/bootstrap,而不是隻是bootstrap

+0

嗨,實際上,我沒有改變它在工作的時間和它不是的時間之間的一行代碼......並且控制檯此刻沒有顯示任何數據表錯誤,這是不尋常的,我已經調用了datatables函數,並且表不是以數據表的方式呈現的。 – Abram

+0

看我的編輯。謝謝 – Abram

+0

我想現在發生的事情是你的JavaScript沒有按照正確的順序加載。我會在更多信息回家時更新我的​​答案。 –

0

這是什麼環境發生?嘗試在env/production.rb中運行config.assets.enabled = true或運行其中的任何環境。默認情況下,此設置在生產中處於關閉狀態。

+0

一切都是正常的發展,然後我試着耙資產:預編譯爲heroku ..當我檢查我的生產應用程序的問題正在發生,當我去檢查我的開發應用程序它也被打破。 – Abram

+0

看到我的編輯,謝謝。順便說一句,我嘗試將該行添加到我的development.rb中,但仍然沒有成功 – Abram