2011-12-28 27 views
1

我想開始使用Twitter Bootstrap for Rails。 popover()函數完全不起作用。什麼都沒發生。Twitter Bootstrap.popover()函數不能在Rails中工作

layouts/application.html.erb

<!DOCTYPE html> 
<html> 
<head> 
<%= stylesheet_link_tag "application" %> 
<%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-buttons.js"  %> 
<%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-twipsy.js" %> 
<%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-popover.js" %> 
<%= csrf_meta_tags %> 
<script> 
$(function() { 
    $("a[rel=popover]") 
    .popover({ 
     offset: 10 
    }) 
    .click(function(e) { 
      e.preventDefault() 
    }) 
    }); 
</script> 
</head> 
<body> 
<%= yield %> 
</body> 
</html> 

這裏是我的我的views/test/test.htlm.erb的一部分:

<li> 
    <a data-placement="below" 
     class="btn danger span2" 
     data-content="This is a test" 
     href="#"   
     rel="popover">+ Test</a> 
</li> 

我的Gemfile的部分:

gem 'rails', '3.1.3' 
gem 'jruby-openssl' 
gem 'json' 
group :assets do 
    gem 'sass-rails', '~> 3.1.5' 
    gem 'coffee-rails', '~> 3.1.1' 
    gem 'uglifier', '>= 1.0.3' 
    gem 'jquery-rails' 
end 

我也試圖複製/粘貼在我的application.js文件twipsy.jspopover.js,並把它與調用我的佈局/ application.html.erb:

<%= javascript_include_tag "application" %> 

我缺少什麼?有任何想法嗎?

+0

是jQuery的還包括您的網頁上? – Pierre 2011-12-29 05:12:09

回答

1

的問題是與你的選擇你使用:

$("a[rel=popover]") 

這jQuery選擇整個rel屬性相匹配,並根據Bootstrap bug report,Rails添加附加屬性的rel標籤,像nofollow

嘗試使用這個選擇來代替:

$("a[rel*=popover]") 
+0

嗨Jared,Tks爲您的迴應。實際上$(「a [rel = popover]」)與軌道很好地合作。我在鏈接到jquery庫時出錯了。我用