简体   繁体   English

Rails 3.x Assets Pipeline Facebox jQuery插件(如何设置)

[英]Rails 3.x Assets Pipeline Facebox jQuery Plugin (how to set up)

I've been banging my head against the wall all night trying to figure out why the jQuery Facebox Plugin won't work in my Rails app. 我整夜都在脑海中摸索,试图弄清为什么jQuery Facebox插件在我的Rails应用程序中不起作用。 This is the error I'm getting, calling this from within doc ready: 这是我得到的错误,可以在doc ready中调用:

$.facebox("<a href='#'>hello</a>");

I have a feeling it's something to do with assets pipeline, but not sure. 我觉得这与资产流水线有关,但不确定。 This is how I've set up the needed files: 这就是我设置所需文件的方式:

vendor/assets/images/facebox/
./loading.gif
./closelabel.png

vender/assets/javascripts/facebox/
./facebox.js

vender/assets/stylesheets/facebox/
./facebox.css

then in my application.css 然后在我的application.css中

...
*= require_self
 *= require_tree .
 *= require_tree ../../../vendor/assets/stylesheets/.
...

then in my application.js 然后在我的application.js中

...
//= require jquery
//= require jquery_ujs
//= require_tree ../../../vendor/assets/javascripts/.
//= require_tree .
...

throws this javascript error: 引发此javascript错误:

TypeError: Object function ( selector, context ) {// The jQuery object is actually just the init constructor 'enhanced'return new jQuery.fn.init( selector, context );} has no method 'facebox'

Just use the facebox-rails gem and your life will improve immensely. 只需使用facebox-rails gem ,您的生活就会大大改善。

Since this took me 2 hours of frustration trying to figure out, I figured I would post my solution, which took me all of 2 minutes to set up. 由于这花了我2个小时的时间来试图弄明白,所以我觉得我会发布我的解决方案,这花了我2分钟的全部时间来完成设置。

I really like the solution of putting it into a gem as well because you don't have to go through the pain of splitting all the files up and making sure you put them in the right place and configured the paths. 我也非常喜欢将其放入gem的解决方案,因为您不必费心分解所有文件,并确保将它们放在正确的位置并配置路径。 Since I use this popup across all my projects, it really comes in andy. 由于我在所有项目中都使用了此弹出式窗口,因此它确实来自安迪。 Seriously, thanks to the guys who made this gem! 认真地,感谢创造了这个宝石的家伙!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM