Bootstrap Dropdown May Not Open

Asked 2 years ago, Updated 2 years ago, 86 views

*Problem
I have deployed a drop-down menu in the header in Bootstrap nav, but I am troubled that the drop-down may or may not open.

Navbar currently has links to the Home and Edit screens (in drop-downs), but the drop-down menu stops working immediately after transitioning to those links.However, when you reload (update) your browser, the drop-down menu starts to work.

*What you did
I thought it might be a problem with js, so I looked it up, but I couldn't find the right materials and it hasn't been solved yet.

I have attached the code below.Thank you for your cooperation.

routes.rb

Rails.application.routes.drawdo
 root'static_pages#home'
 get'/help'=>'static_pages#help'
 get '/about' = > 'static_pages #about'
 get'/contact'=>'static_pages#contact'
 get'/signup'=>'users#new'
 get'/login'=>'sessions#new'
 post '/login' = > 'sessions#create'
 delete '/logout' = > 'sessions#destroy'
 resources —users
 resources:account_activities, only:[:edit]
 resources:password_resets,only:[:new,:create,:edit,:update]
end

_header.html.erb

<nav class="navbar navbar-fixed-top navbar-expand-lg navbar-dark bg-primary">
 <div class="container">
  <a href="/"class="navbar-brand">
   Body-Weight App
  </a>
  <ul class="navbar-nav">
   <%if logged_in?%>
    <li><a href="/"class="nav-link">Home</a><li>
    <li><a href="#"class="nav-link">Help</a></li>
    <lic class="dropdown">
      <a href="#" class="nav-link dropdown-toggle" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" >
        Account <span class="caret"></span>
      </a>
       <div class="dropdown-menu"aria-labeledby="navbarDropdown">
         <a href="/users/<%=current_user.id.to_s%>/edit" class="dropdown-item">Settings</a>
         <div class="dropdown-divider"></div>
         <a class="dropdown-item" rel="nofollow" data-method="delete" href="/logout">Log Out</a>
       </div>
    </li>
  <%else%>
    <li><a href="#"class="nav-link">Help</a></li>
  <%end%>
</ul>


_head.html.erb

<head>
 <title><%=full_title(yield(:title))%></title>
 <%=csrf_meta_tags%>

 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"crossorigin="anonymous">

 <%=stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'%>
 <%=javascript_include_tag 'application', 'data-turbolinks-track': 'reload'%>
</head>

application.html.erb

<!DOCTYPE html>
 <html>
  <%=render "layouts/head"%>
  <body>
   <%=render "layouts/header"%>
   <div class="container">
    <%=render "layouts/flash"%>
    <%=yield%>
    <%=render'layouts/footer'%>
  </div>
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"crossorigin="anonymous">/script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"crossorigin="anonymous"></script;
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"crossorigin="anonymous">/script>
  </body>
</html>

application.js

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file with this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referred here using a relative path.
//
// It's not available to add code directly here, but if you do, it'll appear at the bottom of the bottom of the
// compiled file.JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details)
// about supported directives.
//= require rails-ujs
//= require turbolinks
//= require_tree.
//= require jquery3
//= require popper
//= require bootstrap-sprockets

application.scss

/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file with this directory, lib/assets/style sheets, or any plugin's
 * vendor/assets/stylesheets directory can be referred to here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the bottom of the
 * compiled files so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generically better to create a new file per style scope.

 */
 @import 'bootstrap';



 $main-blue:#428bca;
 $light-gray: #777777;

 li{
   list-style: none;
 }


 .dropdown-item{
   color:$main-blue;
 }


 .footer{
   margin-top —100px;
   border-top —1px solid $main-blue;
   small{
     float:left;
     color:$main-blue;
   }
   ul{
     float:right;
   }
   li{
     float:left;
     margin-left —15px;
   }
   a{
     color:$main-blue;
   }
 }

javascript ruby-on-rails bootstrap bootstrap4

2022-09-30 21:40

1 Answers

Self-Solving
It was caused by the introduction of cdn even though it was already introduced in Gem.


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.