2016-02-23 52 views
0

由于安全更新,我正在为Rails 4.2.5重写Rails 4.2.2应用程序。我在4.2.2应用程序中运行Ruby 2.2.2。在4.2.2应用程序中,我使用gem twitter-bootstrap-rails用于Bootstrap 2.不幸的是,由于Ruby错误,我不能再在Rails 4.2.5中使用该版本的gem。我在GitHub上提交了一个问题,但没有人回应。我决定把我的应用程序升级到2.3.0的Ruby和Rails 4.2.5.1和使用宝石Twitter的引导护栏我的代码使用最新版本的宝石引导,萨斯的自举2.如何在Rails中编写Popover 4.2.5使用gem bootstrap-sass(Bootstrap 2)?

在我的旧应用程序成功地显示了一个部分作为popover。下面的代码示例在使用bootstrap-sass的4.2.5应用程序中。

CSS

app/assets/stylesheets/custom.css.scss 

@import "bootstrap"; 

.popover { max-width: none; } 

JS

app/assets/javascripts/bootstrap.js.coffee (created by gem twitter-bootstrap-rails) 

jQuery -> 
    $(".popover-map").popover({ html : true }) 
    # $("a[rel~=popover], .has-popover").popover() 

app/assets/javascripts/application.js 

//= require bootstrap 

Rails的部分代码

<%= link_to("#{t :map_marfa_head}" , '#', class: "popover-map", rel: "popover", title: "#{t :map_marfa_head}", :"data-placement" => "bottom", :"data-content" => "#{render 'pages/map_marfa'}") %> 

我检查了那里我的Rails部分代码是页面的源代码,看到下面的错误。

TypeError: $(".popover-map").popover is not a function. (In '$(".popover-map").popover({ 
     html: true 
    })', '$(".popover-map").popover' is undefined) 
(anonymous function)bootstrap.self-a54a326f6cd027d08c61488151646f3b32c14ca968788b351d38b24c02b72000.js:2 
firejquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3232 
fireWithjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3362 
readyjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3582 
completedjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3617 

看起来popover函数是未定义的,但错误措辞的方式我不确定。如何在Rails中包含popover脚本?我是否需要在样式表中添加额外的导入语句,或者是否需要创建popover.js/popover.js.coffee/popover.coffee文件? bootstrap-sass gem GitHub文档说默认包含了整个Bootstrap包,但有些东西需要初始化。

我发现这个链接,但它不包含Rails的具体信息。

http://www.w3resource.com/twitter-bootstrap/popover-tutorial.php

UPDATE 2016年2月23日上午10:55 CST

我决定将以下语句添加到应用程序/资产/ Java脚本/ bootstrap.js.coffee因为通常这段代码工作。

$("a[rel=popover]").popover() 

不幸的是,我在这个声明中也得到了以下错误。

TypeError: $("a[rel=popover]").popover is not a function. (In '$("a[rel=popover]").popover()', '$("a[rel=popover]").popover' is undefined) 
(anonymous function)bootstrap.self-dd0727b0d7b4d50d5415be2857e6060f1fc2b8a195352a28af1f44d5b97ec59c.js:2 
firejquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3232 
fireWithjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3362 
readyjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3582 
completedjquery.self-c64a74367bda6ef8b860f19e74df08927ca99d2be2ac934e9e92d5fd361e0da4.js:3617 

Rails中使用引导,萨斯当我还在寻找岗位此错误。我搜索了GitHub文档并发布了这些宝石的章节,并且完全没有任何东西可以帮助我。

我会继续寻找。

回答

0

在我最初尝试在Ruby 2.2.2和Rails 4.2.5中使用twitter-bootstrap-rails之后,我看到了Ruby的安全更新。我升级了Ruby到2.3.0。我在GitHub中提交了这个问题,但从未分配过。由于没有人做出回应,我决定再次尝试twitter-bootstrap-rails,popover像以前一样工作。看来Bootstrap 2的bootstrap-sass不再具有popover或tooltip的脚本。

相关问题