Bootstrap下拉菜单不能在Rails中工作

问题描述:

我想在我的Rails应用程序中实现下拉菜单。我已经复制了正确的代码来显示下拉菜单,但是当我尝试点击菜单时,它没有显示正确的选项。Bootstrap下拉菜单不能在Rails中工作

使用自助CDN:

<!DOCTYPE html> 
<html> 
<head> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <title>Idealprospects</title> 
    <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 
    <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> 
    <%= csrf_meta_tags %> 
</head> 
<body> 

index.html.erb

<div class="container"> 
<h1>Your Prospects</h1> 
<table class="table table-striped table-bordered"> 
    <tr> 
     <th class="center">Company</th> 
     <th class="center">Name</th> 
     <th class="center">Email</th> 
     <th class="center">Telephone</th> 
     <th class="center">Website</th> 
     <th class="center">Action</th> 
    </tr> 

    <% @posts.each do |post| %> 
     <tr> 
     <td><%= post.company %></td> 
     <td><%= post.contact %></td> 
     <td><%= post.email %></td> 
     <td><%= post.telephone %></td> 
     <td><%= post.website %></td> 
     <td> 
      <div class="btn-group"> 
       <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown"> 
       Action <span class="caret"></span> 
       </button> 

      <ul class="dropdown-menu" role="menu"> 
       <li><%= link_to 'Show', post, class: "btn btn-link" %></li> 
       <li><%= link_to 'Edit', edit_post_path(post), class: "btn btn-link" %> 
       <li><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-link" %> </li> 
      </ul> 
      </div> 
     </td> 
     </tr> 
    <% end %> 
</table> 

<br> 

<%= link_to 'New Post', new_post_path, class: "btn btn-link" %> 

</div> 
+0

RailsApps项目有一个很好的rails-bootstrap示例应用程序,它将向您展示如何使用gem和资产管道(建议的做法)将Bootstrap与Rails集成:https://github.com/RailsApps/rails -bootstrap/ –

+0

好的,谢谢你会检查出来。 – Neil

从你的代码,我看到它时需要JS也

http://getbootstrap.com/components/#dropdowns

你只有bootstrap.css包括

下拉菜单

可切换的上下文菜单,用于显示链接列表。制作 与互动下拉式JavaScript插件。

+0

很酷,所以数据切换=“下拉”是必需的这将如何实施使用我的rails代码bceuase他们给我的HTML代码 – Neil

+0

您好,我添加了 – Neil