html - Bootstrap 下拉菜单在 Rails 中不起作用

标签 html css ruby-on-rails twitter-bootstrap

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

使用 bootstrap 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>

最佳答案

从你的代码中我看到你只包含了 bootstrap.css 而它也需要 js

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

下拉菜单

Toggleable, contextual menu for displaying lists of links. Made interactive with the dropdown JavaScript plugin.

关于html - Bootstrap 下拉菜单在 Rails 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22746041/

相关文章:

javascript - 使用 jquery 恢复元素样式

javascript - 在 Rails 中显示闪光通知的最佳方式

html - sql中如何获取奇数节点和偶数节点的值

java - Vaadin 14 时间选择器 - 居中对齐

html - 限制 Bootstrap 中子菜单栏的宽度

javascript - 使用 jquery 定位内联样式不起作用

ruby-on-rails - Sunspot Solr 指定偏移量和限制

css - Rails - 错误 CSS 样式

html - 退出嵌套列表 CSS/HTML 后,将鼠标悬停在菜单列表项上会关闭菜单

html - 仅通过 CSS 在视觉上重新格式化表格行