2016-02-23 51 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的腳本。

相關問題