Rails: Bootstrap dropdown menu not working
I am quite new to Rails and have been following the tutorial by Michael Hartl. Everything has been going along really well until I got to the drop down menu, which was wasn't working, then was working and now isn't working :( I've read several posts and fixes and I suspect my tinkering has gotten to the point where quite simply, I've done something to stop it working. I will say that I initially had the bootstrap-sass 2.x in my gem file, then changed it to 3.x, but went back to 2.x because I didn't realise that going to 3.x would result in issues due to class name changes. So, perhaps the time this was working was when I had bootstrap-sass 3.x installed, not sure. From what I can tell though everything is set up the way it needs to be. I am developing under Windows 8.1 and I had to fix an issue with execjs and in specific the runtimes.rb file. So, here are my details:
//= require jquery //= require jquery_ujs //= require bootstrap //= require turbolinks //= require_tree .
_header.html.erb (where the drop down is)
<header class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <%= link_to "Catered Fit", root_path, id: "logo" %> <!-- <%= link_to image_tag("logo.jpg", width: "25%"), root_path %> --> <nav> <div class="nav pull-right"> <!-- <li><%= link_to "Home", root_path %></li> <li><%= link_to "Help", help_path %></li> --> <% if !signed_in? %> <div class="navbar-form"> <%= form_for(:session, url: sessions_path) do |f| %> <div class="span2 input-xlarge"> <% f.label :email %> <%= f.text_field :email, placeholder: "Email" %> </div> <div class="span2 input-small"> <% f.label :password %> <%= f.password_field :password, placeholder: "Password" %> </div> <div class="span2"> <%= f.submit "Sign in", class: "btn btn-primary" %> </div> <% end %> <% else %> <li><%= link_to "Users", '#' %></li> <li id="fat-menu" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> Account <b class="caret"></b> </a> <ul class="dropdown-menu"> <li><%= link_to "Profile", current_user %></li> <li><%= link_to "Settings", edit_user_path(current_user) %></li> <li class="divider"></li> <li> <%= link_to "Sign out", signout_path, method: "delete" %> </li> </ul> <li><%= link_to "Sign out", signout_path, method: "delete" %></li> </li> <% end %> </div> </nav> </div> </div> </header>
I don't see any errors in the console window and apart from the drop down everything else is working fine.
The following is the source code from the webpage:
<!DOCTYPE html> <html> <head> <title>Ruby on Rails Tutorial Sample App | Dave Williams</title> <link data-turbolinks-track="true" href="/assets/application.css" media="all" rel="stylesheet" /> <script data-turbolinks-track="true" src="/assets/application.js"></script> <meta content="authenticity_token" name="csrf-param" /> <meta content="SlKTCvDr5MFLP0EkthJHQeGIw+Yp0oGUrxvAeQMnVts=" name="csrf-token" /> <!--[if lt IE 9]> <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> </head> <body> <header class="navbar navbar-fixed-top navbar-inverse"> <div class="navbar-inner"> <div class="container"> <a href="/" id="logo">Catered Fit</a> <!-- <a href="/"><img alt="Logo" src="/assets/logo.jpg" width="25%" /></a> --> <nav> <div class="nav pull-right"> <!-- <li><a href="/">Home</a></li> <li><a href="/help">Help</a></li> --> <li><a href="#">Users</a></li> <li id="fat-menu" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown"> Account <b class="caret"></b> </a> <ul class="dropdown-menu"> <li><a href="/users/1">Profile</a></li> <li><a href="/users/1/edit">Settings</a></li> <li class="divider"></li> <li> <a data-method="delete" href="/signout" rel="nofollow">Sign out</a> </li> </ul> <li><a data-method="delete" href="/signout" rel="nofollow">Sign out</a></li> </li> </div> </nav> </div> </div> </header> <div class="container"> <div class="row"> <aside class="span4"> <section> <h1> <img alt="Dave Williams" class="gravatar" src="https://secure.gravatar.com/avatar/387593e03fccc38895fc20a2084e27f5?s=50" /> Dave Williams </h1> </section> </aside> </div> <footer class="footer"> <small> <a href="http://railstutorial.org/">Rails Tutorial</a> by Michael Hartl </small> <nav> <ul> <li><a href="/about">About</a></li> <li><a href="/contact">Contact</a></li> <li><a href="http://news.railstutorial.org/">News</a></li> </ul> </nav> </footer> <pre class="debug_dump">--- !ruby/hash:ActionController::Parameters action: show controller: users id: '1' </pre> </div> </body> </html>
Would really appreciate some help on this to get past this issue.
Thanks in advance, and please let me know if I can provide anymore information.
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require_tree .
Worked like a charm :)
bootstrap drop down-menu not working with rails, Recently, a trainee learning bootstrap comes to me for help asking why the bootstrap drop down menu not working. It took me about 20 minutes If you read Bootstrap's Dropdown JS code, you'll see it adds a click listener to toggle the dropdown menu. If you run this code twice, you're adding two click listeners. So on every click, those two listeners open the menu and suddenly close it again.
bootstrap dropdown menu not working · Issue #14 · railstutorial , hi, i am a beginner and doing the rails tutorial twitter app. My bootstrap dropdown menu is not working. When i do the rspec test, its pass. Bootstrap - dropdown menu not working? Ask Question This is a Rails specific answer, but I had this same problem with Bootstrap dropdown menus in my Rails app
<script> $('.dropdown-toggle').dropdown() </script>
at the botton of your _header file.
Why isn't the Boostrap Dropdown not working in the menu after , Why isn't the Boostrap Dropdown not working in the menu after loging in ? It's your standard bootstrap dropdown, so double check and make sure there are no JS errors in the Want to stay up-to-date with Ruby on Rails? bootstrap drop down-menu not working with rails Recently, a trainee learning bootstrap comes to me for help asking why the bootstrap drop down menu not working. It took me about 20 minutes to figure out the issue. As usual first I tried to see that the HTML structure or markup of menu as required by Bootstrap dropdown.
This works to me:
//= require jquery //= require jquery_ujs //= require turbolinks //= require bootstrap
application.scss: Don't use //= require in scss files
@import "*"; @import "bootstrap"; @import "font-awesome";
rake assets:clean rake assets:precompile
Dropdown menu does not work - Rails, My bootstrape dropdown menu not working. I have no idea why? Gemfile contain: ruby “1.9.3” gem 'rails', '3.2.16' gem 'bootstrap-sass', '2.1' hi, i am a beginner and doing the rails tutorial twitter app. My bootstrap dropdown menu is not working. When i do the rspec test, its pass. But the dropdown menu is not working. please help me. thanks in advance
Using a later version of rails (5.2.3) I found that the instructions given in the book didn't work. The console warned me that jQuery needed to be installed, and by going to https://github.com/rails/jquery-rails I was able to find the instructions to get it up-and-running.
Add to the Gemfile:
Add to application.js
//= require jquery //= require bootstrap
So that the whole Gemfile is
//= require rails-ujs //= require activestorage //= require jquery //= require bootstrap //= require turbolinks //= require_tree .
ruby on rails twitter bootstrap drop down suddenly not working , I found that dropdown js being loaded twice into the asset pipeline seems to open and close the dropdown menu instantly, but would work fine in Heroku/ Some facts I discovered on my Ubuntu + ruby 1.9.3 + rails 3.2.7 + twitter-bootstrap-rails 2.1.1: Changing order of inclusions breaks development mode, so did not changed it.
Bootstrap 4 not working with Ruby on Rails 5 - Help, bootstrap 4 is not working with my ruby on rails 5 app. i have added all the class="dropdown-toggle" data-toggle="dropdown" role="button" When I am re-sizing the browser window toggle button is working fine and dropdown menu is coming properly but the dropdown-submenu is not working in 1024 resolution or in any small size window,