Select2-rails不适用于ActiveAdmin [英] Select2-rails is not working with ActiveAdmin
问题描述
我很难将select2-rails与ActiveAdmin集成在一起。我在
Select2-rails Github页面上执行了设置步骤: https://github.com/argerim / select2-rails ,然后添加以下行:
I have difficulties integrating select2-rails with ActiveAdmin. I followed setup steps on Select2-rails Github page: https://github.com/argerim/select2-rails and I added line:
//= require select2
到 app / assets / javascripts / application.js 并行:
*= require select2
至 app / assets / stylesheets / application.css
所以我认为当我在ActiveAdmin中拥有页面时,我应该能够添加行:
so I assume when I have page in ActiveAdmin I should be able to add line:
$('#add_student_select').select2()
到 active_admin.js.coffee
但是它不起作用。在控制台中,我会看到以下错误:
But its not working. In console I can see following error:
Uncaught TypeError: undefined is not a function
(anonymous function)
fire
self.fireWith
jQuery.extend.ready
completed
我还遵循了 StackOverflow问题,建议添加此内容行到 active_admin.css.scss
:
I also followed this StackOverflow question which recommends to add this line to active_admin.css.scss
:
body.active_admin {
@import "select2";
}
但随后出现以下错误:
File to import not found or unreadable: select2.
是否正确集成?我认为ActiveAdmin甚至无法访问库。
Do I integrate it correctly? I don't think that ActiveAdmin is able to get even access to the librabry.
推荐答案
如果要将Select2添加到ActiveAdmin界面,必须将JavaScript和样式添加到ActiveAdmin资产:
If you're adding Select2 to the ActiveAdmin interface, you must add the javascript and styles to the ActiveAdmin assets:
# app/assets/javascripts/active_admin.js.coffee
#
#= require select2
#
# ...
和样式表:
// app/assets/stylesheets/active_admin.css.scss
//
//= require select2
//
// ...
在您提供的示例中,Select2将对主Rails应用程序可用,但对ActiveAdmin不可用。 ActiveAdmin使用自己的javascript和样式表文件。
In the example you provided, Select2 would be available to the main Rails application, but not ActiveAdmin. ActiveAdmin uses its own javascript and stylesheet files.
这篇关于Select2-rails不适用于ActiveAdmin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!