1

好的,所以我的资产管道突然开始在我的开发机器上运行。以前工作的 JS 函数现在抛出“不是函数”错误。我知道我一定做错了什么。一分钟前,datatables 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) %>   

上面我使用yield从谷歌加载在线脚本,因为它们只在某些页面上需要,如果包含在应用程序布局中,通常会减慢网站速度。我尝试删除产量,但即使在清除浏览器缓存并运行 rake assets:clean (为了安全起见)之后,事情仍然被破坏。

这是 CSS 和元标记之间显示的内容(对于在 yield 脚本头中没有任何内容的页面):

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

天哪,这让我发疯了。不,它仍然无法正常工作。最后一次编辑使一切正常,但随后我再次运行 rake assets:precompile 并推送到 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
4

2 回答 2

3

你确定你没有在 JS 的某处忘记分号吗?资产管道不做任何代码清理......

查看浏览器的 JS 控制台,看看错误出现在哪里...

编辑:好的,我想看看发生了什么。尝试在最后取出require_tree并手动加载您未明确说明的任何其他 JS 文件。最终发生的是require_tree明确列出的任何先前要求的覆盖,并最终按字母顺序加载它们。

另外,我不知道您在 bootstrap.js 中使用什么 gem(或者如果您甚至正在使用一个),但也可以尝试使用twitter/bootstrap而不是仅仅bootstrap

于 2012-11-11T04:27:17.130 回答
0

这是在什么环境下发生的?尝试config.assets.enabled = true在 env/production.rb 或您正在运行的任何环境中进行操作。我相信在生产中默认情况下会关闭此设置。

于 2012-11-11T04:29:21.327 回答