资产管道起作用

时间:2012-11-11 04:24:01

标签: ruby-on-rails

好的,所以我的资产管道突然开始在我的开发机器上运行。以前工作的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) %>   

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

这是CSS和元标记之间出现的内容(对于yield 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:

感谢下面的评论之一,我能够解决这个问题。我不得不重新洗牌应用程序.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上运行..不管你信不信,当我回到我的localhost版本时它被打破了再次,现在又抛出不同的错误而不再加载数据表!

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

2 个答案:

答案 0 :(得分:3)

你确定你没有忘记JS中的某个分号吗?资产管道不进行任何代码清理......

在浏览器的JS控制台中查看错误吐出的位置......

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

另外,我不知道你为bootstrap.js使用了什么样的宝石(或者你是否使用过它),但也尝试使用twitter/bootstrap代替bootstrap

答案 1 :(得分:0)

这种情况发生在什么环境?尝试在env / production.rb或您正在运行的任何环境中执行config.assets.enabled = true。默认情况下,我相信此设置在生产中处于关闭状态。