下拉菜单未在轨道上显示/工作

下拉菜单未在轨道上显示/工作

“SelectDatabase”和“SelectTable”下拉菜单不起作用。

_header.html.erb 文件

<header class="navbar navbar-fixed-top navbar-inverse">
      <div class="container">
        <%= link_to "Database Management", root_path, id: "logo" %>
        <nav>
          <ul class="nav navbar-nav navbar-right">
            <li><%= link_to "Home",   root_path %></li>
            <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            SelectTable <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
            <%  if $l == 1 %>
              <% for items in $selectedtable %>    
                <li><%= link_to items, currenttable_path %> </li> 
                <% $gh = item %>
              <% end %> 
            <% end %>
            </ul>

            <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">
            SelectDatabase <b class="caret"></b>
            </a>
            <ul class="dropdown-menu">
            <% for item in $selecteddatabase %>  
              <li><%= link_to item, currentdatabase_path %></li> 
              <% $gy = item %>
            <% end %>
            </ul>
            <li><%= link_to "NewTable", newtable_path %></li>
            <li><%= link_to "NewDatabase", newdatabase_path %></li>
            <li><%= link_to "DeleteTable", deletetable_path %></li>
            <li><%= link_to "DeleteDatabase", deletedatabase_path %></li>
            <li><%= link_to "Connect", connect_path %></li>
            <li><%= link_to "Disconnect", disconnect_path %></li>
            <li><%= link_to "Administration", administration_path %></li>
            <li><%= link_to "Quit", quit_path %></li>
          </ul>
        </nav>
      </div>
</header>

application.html.erb 文件

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag 'application', media: 'all',
                                           'data-turbolinks-track' => true %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>

  </head>
  <body>
    <%= render 'layouts/header' %>
        <div class="container">
      <% flash.each do |message_type, message| %>
        <%= content_tag(:div, message, class: "alert alert-#{message_type}") %>
      <% end %>
      <%= yield %>
      <%= render 'layouts/footer' %>
      <%= debug(params) if Rails.env.development? %>
    </div>
  </body>
</html>

application_controller.rb 文件

require 'mysql2'
class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  $con = Mysql2::Client.new(host: "localhost", username: "root", password: "new_password", database: "mysql")

  before_filter :assign_header_variables

  def assign_header_variables
    rs = $con.query("SHOW databases")
    i = 0 
    for y in rs
    i = i + 1
    end
    c = 0
    $selecteddatabase = Array.new(i)
    for item in rs 
      $selecteddatabase[c] = item
      c = c + 1
    end

    if $l == 1
      ts = $con.query("SHOW tables")
      i = 0 
      for y in ts
        i = i + 1
      end
      k = 0 
      $selectedtable = Array.new(i)
      for items in ts do 
        $selectedtable[k] = items 
        k = k + 1
      end
    end
  end
end

答案1

我找到了问题的答案。

将 Bootstrap JavaScript 库添加到 application.js。app/assets/javascripts/application.js

  • //= 需要 jquery
  • //= 需要 jquery_ujs
  • //= require bootstrap
  • //= 需要 turbolinks
  • //= 需要树。

相关内容