繁体   English   中英

将jQuery插件添加到Ruby on Rails应用中

[英]Adding a jQuery Plugin into a Ruby on Rails App

我正在使用jQuery插件使用HTML,CSS和JavaScript的网站。 为了使网站更加动态,我将代码转移到了Ruby on Rails。 HTML和CSS都很好,但是我以前使用的某些jQuery插件不再起作用。

我尝试了多种方法来解决此问题。 我首先将javascript文件添加到app/assets/javascripts ,然后在application.js中添加//= require pluginfilename ,然后在<%= javascript_include_tag name..... %>但这没有用。

有什么我想念或做错的事吗? 我是Rails的新手。 这是4.2.3 btw版本。

编辑:这是我的application.js文件

// This is a manifest file that'll be compiled into application.js, which         will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require jquery_ujs
//= require bootstrap.min
//= require turbolinks
//= require countdown
//= require grid
//= require custom
//= require script
//= require_tree .

我要做的第一件事是尝试找到通过CDN分发的插件版本,然后通过<%= javascript_include_tag链接%>包含它。

除非...

您是否执行// =要求不带扩展名的pluginfilename? 您可以粘贴到application.js文件中,以便我们看看吗?

另外,您遇到了JS控制台错误? 您是否确定在使用插件之前已将其加载? (application.js文件中的加载顺序很重要。)

您可以通过Rails-Assets.org在Bower和Rails之间找到一座桥梁。 我已经将此用于多个项目,并且效果很好。 如果您的插件使用Bower,则它们应该存在于Rails-Assets.org上

暂无
暂无

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

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