ActiveAdmin 与 Rails 3.1 破坏了 javascript
我刚刚用我的 Rails 3.1 应用程序实现了 ActiveAdmin gem,它导致了我的应用程序中允许 ajax 发布评论的一些 javascript 的问题。删除 active_admin.js 文件会导致问题消失。如何保留 active_admin 的 javascript,同时保留应用程序的功能?关于可能出现的问题有什么想法吗?
active_admin.js 的内容:
//= require active_admin/base
我的 application.js 文件的内容:
//= require jquery
//= require jquery_ujs
//= require_tree .
ActiveAdmin 破坏的 Javascript:
jQuery ->
$('.addcomment').live("click", ->
$(this).closest('.comment_area').find('.add_comment_box').parent().removeClass("add_comments_box_hidden").addClass('add_comments_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_comment_btn').live("click", ->
$(this).closest('.comment_area').addClass('add_comment_here')
$.post(
'/comments'
$(this).closest('form').serialize()
null
"script"
)
return false )
链接到 active_admin github 页面。
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 comments. 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 ->
$('.addcomment').live("click", ->
$(this).closest('.comment_area').find('.add_comment_box').parent().removeClass("add_comments_box_hidden").addClass('add_comments_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_comment_btn').live("click", ->
$(this).closest('.comment_area').addClass('add_comment_here')
$.post(
'/comments'
$(this).closest('form').serialize()
null
"script"
)
return false )
Link to active_admin github page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不知道这是否会对您有帮助...我也将 active_admin 的 javascript 与 active_admin 应用程序分开使用。我在单击“ajax 链接”时遇到了双重请求的问题。该问题是由vendor.js 文件中的触发器引起的。最新版本的 gem(vendor.js 已被删除)和我的 application.js 文件中的正确包含语句已修复此问题。
我建议您将
//=require_tree .
替换为显式 require 语句。尝试一一添加您的部门,直到找到问题为止。此外,请向我们提供您正在使用的 ActiveAdmin 版本。
I 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.
问题是 ActiveAdmin 包含它自己的 jQuery 版本,它会覆盖您的版本。如果您向 jQuery 添加了任何插件,它们就会消失。
幸运的是,有一个简单的修复方法 - 不要显式包含 ActiveAdmin 的任何 javascript。你不需要。 Active Admin 知道从 ActiveAdmin gem 中提取所需的 javascript。因此,只需删除该 require 行就可以了。
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.
当您删除 active_admin.js 中的 require 行时,索引中的删除或更新链接(default_actions)不起作用,因此将该行设置为:
将
//= require_tree .
替换为中的确切 js 文件你的资产一一。这终于解决了我的问题!希望它能为某人节省一些时间。
问候
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