I just implemented the ActiveAdmin gem with my Rails 3.1 app, and it caused a problem with some javascript I have in my app which allows ajax posting of ments. Removing the active_admin.js file causes the problem to go away. How do I keep the active_admin's javascript while preserving the functionality of my app? Any ideas on what the problems may be?
Contents of active_admin.js:
//= require active_admin/base
Contents of my application.js file:
//= require jquery
//= require jquery_ujs
//= require_tree .
Javascript that is being broken by ActiveAdmin:
jQuery ->
$('.addment').live("click", ->
$(this).closest('ment_area').find('.add_ment_box').parent().removeClass("add_ments_box_hidden").addClass('add_ments_box')
return false )
init_csrf = ->
window._settings.token = $('meta[name="csrf-token"]').attr 'content'
$.ajaxSetup
beforeSend: (xhr) ->
xhr.setRequestHeader "X-CSRF-Token", _settings.token
jQuery ->
$('.post_ment_btn').live("click", ->
$(this).closest('ment_area').addClass('add_ment_here')
$.post(
'/ments'
$(this).closest('form').serialize()
null
"script"
)
return false )
Link to active_admin github page.
I just implemented the ActiveAdmin gem with my Rails 3.1 app, and it caused a problem with some javascript I have in my app which allows ajax posting of ments. Removing the active_admin.js file causes the problem to go away. How do I keep the active_admin's javascript while preserving the functionality of my app? Any ideas on what the problems may be?
Contents of active_admin.js:
//= require active_admin/base
Contents of my application.js file:
//= require jquery
//= require jquery_ujs
//= require_tree .
Javascript that is being broken by ActiveAdmin:
jQuery ->
$('.addment').live("click", ->
$(this).closest('.ment_area').find('.add_ment_box').parent().removeClass("add_ments_box_hidden").addClass('add_ments_box')
return false )
init_csrf = ->
window._settings.token = $('meta[name="csrf-token"]').attr 'content'
$.ajaxSetup
beforeSend: (xhr) ->
xhr.setRequestHeader "X-CSRF-Token", _settings.token
jQuery ->
$('.post_ment_btn').live("click", ->
$(this).closest('.ment_area').addClass('add_ment_here')
$.post(
'/ments'
$(this).closest('form').serialize()
null
"script"
)
return false )
Link to active_admin github page.
Share edited Jan 20, 2012 at 1:08 John asked Jan 20, 2012 at 0:48 JohnJohn 13.8k14 gold badges54 silver badges73 bronze badges3 Answers
Reset to default 6I don't know if this will help you ... I'm also using active_admin's javascript separately from the active_admin app. I faced a problem with double requests on clicking to "ajax links". The problem was caused by triggers in the vendor.js file. This has been fixed with the latest version of the gem (vendor.js has been removed) and proper inclusion statements in my application.js file.
I would suggest you to replace //=require_tree .
with explicit require statements. Try one by one to add your deps till you find the problem.
Moreover, please provide us with the version of ActiveAdmin that you are using.
The problem is ActiveAdmin includes its own version of jQuery, which overrides your version. If you've added any plugins to jQuery, they will disappear.
Luckily there's an easy fix - don't explicitly include any javascript for ActiveAdmin. You don't need to. Active Admin knows to pull the javascript it needs from the ActiveAdmin gem. So just delete that require line and you should be fine.
When you delete require line in active_admin.js, than delete or update link(default_actions) in index doesn't work, so let that line be and:
Replace //= require_tree .
with exact js files in your assets one by one. This finally solved my problem !
Hope it'll save some time to someone. Regards