我无法在我的应用程序中运行引导开关。
在我的gemfile中,我有
gem 'bootstrap-switch-rails', '~> 3.0.0'
在我的application.html.haml中(我放了一个断点:它在加载后执行)
:javascript
$(function() {
$('input:checkbox').bootstrapSwitch();
});
在我的application.css中我有
*= require_directory .
*= require_self
*= require_directory ./../fonts
*= require bootstrap3-switch
在我的application.js中我有
//= require bootstrap
//= require bootstrap-switch
//= require turbolinks
//= require_tree .
最后,在我的视图代码中,我有以下3次尝试:
= form_for(group) do |g|
= g.label :is_private, "is_private"
= g.check_box :is_private, :data => { :size=>'small', 'on-color'=>'success', 'on-text'=>'YES', 'off-text'=>'NO' }
%input{ :type => "checkbox", :name => "mycheckbox" }
.switch{ "data-on" => "primary", "data-off" => "info"}
%input{ :type => "checkbox" }
结果始终是标准复选框。
任何人都可以建议我错在哪里?
答案 0 :(得分:0)
好吧,我解决了,但我不确定这是不是正确的方法。
我需要插入以下行
:javascript
$(function() {
$('input:checkbox').bootstrapSwitch();
});
到任何我想使用开关的.html.haml文件中。
这对我来说很奇怪,因为我已经在我的application.html.haml中插入了相同的代码,这应该足够了。
如果有更好的建议请发布。