javascript函数可通过javascript_include_tag获得,但不包括资产管道和application.js [英] javascript functions available via javascript_include_tag but not asset pipeline and application.js

查看:160
本文介绍了javascript函数可通过javascript_include_tag获得,但不包括资产管道和application.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,如果这已经发布到别处,但我不确定如何甚至短语搜索这个问题。



基本上,我已经获得 fullcalendar.js 坐在 app / assets / javascripts / 中。在我的 application.js 文件中(当然在同一个文件夹中),我有以下内容...

  // =需要jquery 
// =需要jquery_ujs
// =需要基础
// = require_tree。

因此,如预期的那样 fullcalender.js 在资产编译过程中被清除,并最终在 application.js 中被提供给用户。



当我尝试引用 fullcalendar.js 中定义的函数时(因此在 application.js 在编译资源之后),它会在firebug的js控制台中引发一个错误,指出 TypeError:$(...)。fullCalendar不是函数,当然也是满日历不会呈现。



现在,如果我包含<%= javascript_include_tagfullcalendar.js%> 按预期工作。

挡住了,我查看了每个文件中的js并对它们进行比较,结果看不出有什么区别。资产管道是否有某些我不知道的东西,或者这是一个怪异的DOM问题?在这一点上,我只是不知道。



作为参考,这里是 application.js fullcalendar.js ,并链接到网站的网页来源。我只包括每个相关的完整日历部分,因为如果我包含所有内容,它对于要点或pastebin来说太大了。



让我感到困惑的是,从同一个文件中,一个直接链接到另一个文件,另一个流过资产管道流程。

application.js - http://pastebin.com/byyNErB8



fullcalendar.js - http://pastebin.com/k4p29YmP

任何见解或帮助都将非常感激。

p>也许是依赖性错误。我建议你对这样的lib使用更好的做法。


  1. 将fullcalendar脚本放入 vendor / assets / javascripts


  2. 在tree.jquery和任何其他依赖的lib之前,需要在application.js中手动执行此脚本。

      / = require'fullcalendar` 


添加

检查加载的Javascript文件在头文件中,如果application.js是最后一个,则会出现依赖关系错误。在调用它之前,lib必须在那里。


My apologies if this has been posted somewhere else, but I'm not exactly sure how to even phrase a search for this problem.

Basically, I've got fullcalendar.js sitting in app/assets/javascripts/. Within my application.js file (in the same folder of course) I've got the following...

//= require jquery
//= require jquery_ujs
//= require foundation
//= require_tree .

So, as expected the fullcalender.js gets swept up in the asset compiling process and ends up in the application.js that is then served to the user.

The problem comes in when I try to reference a function defined in fullcalendar.js (and thus defined in application.js after compiling the assets) it throws an error stating TypeError: $(...).fullCalendar is not a function in the js console of firebug, and of course full calendar doesn't render.

Now, however, if I include <%= javascript_include_tag "fullcalendar.js" %> in the layout file after all of the other scripts and stylesheets have been pulled in, it works as expected.

Baffled, I looked into the js in each file and compared them and can't see a difference. Is there something going on with the asset pipeline that I'm not aware of or is this some freaky DOM issue? I just have no idea at this point.

For reference, here are the contents of both the application.js and fullcalendar.js that are linked to in the page source of the site. I've only included the relevant full calendar portion of each, as it's too large for gist or pastebin if I include everything.

What baffles me is that both the sources come from the same file, one is just linked to directly, the other flows through the asset pipeline process.

application.js - http://pastebin.com/byyNErB8

fullcalendar.js - http://pastebin.com/k4p29YmP

Any insight or help would be GREATLY appreciated.

解决方案

Maybe a dependency error. I'll suggest you to use a better practice for such lib.

  1. Put the fullcalendar scripts into vendor/assets/javascripts

  2. Require this script manually in application.js before the tree and after jquery and any other lib it depends.

    /=require 'fullcalendar`
    

Add

Check the loaded Javascript files in header, if application.js is the last, you have dependency error. The lib must be there before calling it.

这篇关于javascript函数可通过javascript_include_tag获得,但不包括资产管道和application.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆