Activeadmin stops jQuery

I use jquery drag and drop in my application and it works fine.

Then I added activeadmin and stopped jquery.

I get this error

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

If I remove this line from active_admin.js

 //= require active_admin/base 

he starts working again.

Any ideas?

+6
source share
4 answers

If you look at the activeadmin base manifest file, you will see where the additional jquery download is called. The final call in the base manifest is the activeadmin application manifest. Therefore, there is an easy way to get around unwanted extra jquery loading.

Change this line in application / app / assets / javascripts / active _admin.js:

 //= require active_admin/base 

For

 //= require active_admin/application 

This way the active javascript admin code will be loaded without restarting jquery.

Inside / admin space, the active admin loads active_admin.js without loading application.js, so you also need to download application.js. In order to work, you need to make active download admin.js to 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} 

However, please note that for this to work, you may need all these declarations in the app.js application manifest:

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

Also, when application.js is loaded into the active admin, you need to manage any namespace conflicts yourself.

+9
source

The current release of Gem Active admin has an extra copy of jquery included through // = require active_admin / base. This caused a lot of problems for people who already have jquery that they reference in their application.

For detailed information and possible solutions, see this request to download the active admin. Request Pull # 468

+2
source

Try moving the active_admin.js file to the vendor / assets / javascripts folder of your Rails project: you should be fine.

Please let us know if this helped someone!

Hi

+2
source

I had an error with the code above, so I changed my version a bit:

active admin init:

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

active admin js

  //= require active_admin/base 

What is it!

-1
source

Source: https://habr.com/ru/post/905513/


All Articles