Activeadmin停止我的jQuery工作 [英] Activeadmin stops my jQuery working

查看:47
本文介绍了Activeadmin停止我的jQuery工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在我的应用程序中使用jquery拖放操作,它工作正常。

I'm using jquery drag and drop in my app and it works fine.

然后我添加了activeadmin,它停止了我的jquery工作。

I then added activeadmin and it stops my jquery working.

我收到此错误

$(".draggable_article_image").draggable is not a function

如果我从active_admin.js中删除此行

If I remove this line from active_admin.js

//= require active_admin/base

it重新开始工作。

有什么想法吗?

推荐答案

activeadmin基本清单文件中,您会看到额外的jQuery负载被调用。基本清单中的最后一个调用是对activeadmin应用程序清单的调用。因此,有一种简单的方法可以绕过不必要的额外jquery负载。

If you look at the activeadmin base manifest file you'll see where the additional jquery load is called. The last call in the base manifest is to the activeadmin application manifest. Therefore there is an easy way to bypass the unwanted additional jquery load.

在应用程序的/app/assets/javascripts/active_admin.js中更改此行:

Change this line in you application's /app/assets/javascripts/active_admin.js:

//= require active_admin/base

To

//= require active_admin/application

那样,将在不重新加载jquery的情况下加载活动管理员的javascript代码。

That way active admin's javascript code will be loaded without reloading jquery.

在/ admin空间中,活动管理员将加载active_admin.js而不加载application.js,因此您也需要在其中加载application.js。要工作,您需要在active_admin.js之前进行活动的管理员加载application.js。将此添加到config / initializers / active_admin.rb:

Within the /admin space, active admin loads active_admin.js without loading application.js, so you need to load application.js there too. To work, you need to make active admin load application.js before active_admin.js. Add this to config/initializers/active_admin.rb:

current_javascripts = config.javascripts.clone
config.clear_javascripts! 
config.register_javascript 'application.js'
current_javascripts.reverse.each{|j| config.register_javascript j}

但是,请注意,要使其无缝运行,您可能需要所有这些声明在应用程序的application.js清单中:

However, note that for this to work seamlessly, you may need all these declarations in your app's application.js manifest:

//= require jquery
//= require jquery-ui
//= require jquery_ujs

此外,由于application.js正在活动管理员中加载,因此您需要自己管理任何名称空间冲突。

Also as application.js is being loaded within active admin, you need to manage any namespace conflicts yourself.

这篇关于Activeadmin停止我的jQuery工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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