3

how do I make bootstrap work on my custom layouts in rails 6

I have install bootstrap with the yarn add bootstrap jquery popper.js command and configured my the ..app/config/webpack/environment.js as follow.

const { environment } = require('@rails/webpacker') const webpack = require('webpack') environment.plugins.append('Provide', new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', Popper: ['popper.js', 'default'] }) ) module.exports = environment 

..app/javascript/packs/application.js

... import 'bootstrap' import "../stylesheets/application" 

..app/javascript/stylesheets/application.scss

@import '~bootstrap/scss/bootstrap'; 

Everything works fine but when I created another layout file,the layout does not import the bootstrap library.

..layout/visitor.html.erb

<html> ..... <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> .... 

The bootstrap library is not loaded in this visitor.html.erb layout it is loaded only in the application.html.erb layout file.

how to fix the problem

1 Answer 1

4

you need change

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

to

<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>

Sign up to request clarification or add additional context in comments.

4 Comments

I have change the <%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> but did not still work
not in visitor.html.erb but i mean in application.html.erb
@foliwe83 your vote down make me try again :) . but work finally .
sorry about that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.