簡體   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