I
I
IlyaMalyukov2020-11-16 22:25:52
Ruby on Rails
IlyaMalyukov, 2020-11-16 22:25:52

Why is Bootstrap's dropdown not working in Rails?

_header.html.erb

<header class="navbar navbar-fixed-top navbar-inverse">
<div class="container">
  <%= link_to "sample app", root_path, id: "logo" %>
    <nav>
      <ul class="nav navbar-nav navbar-right">
        <li><%= link_to "Home", root_path %></li>
        <li><%= link_to "Help", help_path %></li>
        <% if logged_in? %>
          <li><%= link_to "Users", '#' %></li>
          <li 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", '#' %></li>
          <li class="divider"></li>
          <li>
            <%= link_to "Log out", logout_path, method: "delete" %>
          </li>
        </ul>
      </li>
    <% else %>
      <li><%= link_to "Log in", login_path %></li>
    <% end %>
      </ul>
    </nav>
  </div>
</header>


application.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= requireturbolinks
//= require_tree


connected in scss
@import "bootstrap-sprockets";
@import "bootstrap";

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zaporozhchenko Oleg, 2020-11-16
@c3gdlk

sprockets and webpacker are just add-ons that solve a bunch of problems when working with assets.
When something goes wrong, the algorithm is as follows:
1. Create a clean prototype on HTML / CSS / JS + the necessary libs
2. Use the browser's dev tools to see what doesn't match what the rails generates: library version ( gems and packages may be different from examples), DOM path, generated scripts, javascript order, and so on. You need to understand what exactly is the problem.
3. Read the doc for a specific tool to understand how to make it work the way you want. Well, or ask here already a more specific question. Like here is such and such a code, you need to generate code such and such, and another is generated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question