2016-04-08 37 views
0

我想弄清楚如何让我的Rails 4应用程序中的弹出工作。Rails 4 - Bootstrap Popovers - js不工作

我在我的应用程序中有bootstrap-sass gem。按照文件,我已经列入我的application.js文件中的以下内容:

/= require jquery 
//= require bootstrap 

我也曾尝试调换需要引导的需要引导链轮(但是它没有什么区别)。

我在我的JavaScript的另一个文件夹名为organisations.js.coffee,具有:

$('label-with-popover').popover(placement: 'right') 

在我看来,我试图让酥料饼的工作,我有:

<button type="button" class="label-with-popover" class="btn btn-default" data-toggle="popover" data-placement="top" data-content="netwerewerwrwe" data-title="test"><i class="fa fa-info-circle"></i></button> 

当我尝试这个时,当我点击它时,按钮什么也不做。

任何人都可以看到什么需要发生得到这个工作?我不确定是否应该在咖啡文件中放置脚本标记。我试过了,但对这个问题没有任何影响。

+0

您应该只定义一次类 - 即'class =“label-with-popover btn btn-default”'。有些浏览器只会采用最后一个类的声明,这可能是为什么jquery无法找到它? –

回答

0

你没有在你的jQuery中使用正确的选择器,所以popover没有被应用到正确的类。您需要:

$('.label-with-popover').popover(placement: 'right'); 

在您刚刚选择一个不存在的元素label-with-popover之前。您需要选择类.label-with-popover

+0

我试过了,但它不起作用。当我点击按钮时没有任何反应。我可以在我的控制台检查器中看到以下错误消息:10TypeError:$不是函数。 (在'$(document)'中,'$'未定义) – Mel

+0

然后你没有jQuery。不知道以上是否是一个错字,但你需要它是2斜线:'// = require jquery' – digitalEyes

+0

这是一个错字。我有两个斜杠。我如何让jQuery工作?我有其他jQuery资产工作。 – Mel