[RUBY] Ich habe Bootstrap in Rails6 eingefügt. (Sprockets :: Rails :: Helper :: AssetNotPrecompiled Handling)

Gemfile hinzugefügt

Gemfile


gem 'uglifier'
gem 'jquery-rails'
gem 'bootstrap'
bundle install

Stellen Sie sicher, dass die JS-Datei in der Produktionsumgebung komprimiert ist.

/config/environments/production.rb


config.assets.js_compressor = :uglifier

Erstellen Sie ein Verzeichnis: Javascripts unter Assets, erstellen Sie eine neue application.js und fügen Sie sie hinzu.

app/assets/javascripts/application.js


//= require jquery3
//= require popper
//= require bootstrap

Benennen Sie application.css unter Stylesheets in application.scss um und fügen Sie hinzu.

app/assets/stylesheets/application.scss


@import "bootstrap";

In Layout laden

html:app/views/layouts/application.html.erb


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

In meiner Umgebung wurde die Fehlermeldung Sprockets :: Rails :: Helper :: AssetNotPrecompiled angezeigt, daher habe ich sie hinzugefügt.

config/initializers/assets.rb


Rails.application.config.assets.precompile += %w( application.js )

Sie haben jetzt bestätigt, dass Bootstrap angewendet wurde.

スクリーンショット 2020-11-15 12.49.07.png

Recommended Posts

Ich habe Bootstrap in Rails6 eingefügt. (Sprockets :: Rails :: Helper :: AssetNotPrecompiled Handling)
Aktivieren Sie jQuery und Bootstrap in Rails 6 (Rails 6).
[Rails 6] Passen Sie Bootstrap in der Rails + Bootstrap 5.0.0-Alpha-Umgebung an
Wo ich im heutigen "Rails Tutorial" (2020/10/08) stecken geblieben bin
Ich habe versucht, die Sitzung in Rails zu organisieren
Wo ich im heutigen "Rails Tutorial" (2020/10/05) stecken geblieben bin
Wo ich im heutigen "Rails Tutorial" (2020/10/06) stecken geblieben bin
Wo ich im heutigen "Rails Tutorial" (2020/10/04) stecken geblieben bin
Wo ich im heutigen "Rails Tutorial" (2020/10/07) stecken geblieben bin