1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ruby on rails6にbootstrapを導入 

Last updated at Posted at 2021-09-06

#ruby on rails にbootstrapを使うときのコマンド

rails等のバージョン
ruby 2.7.4p191 (2021-07-07 revision a21a3b7d23) [x64-mingw32]
Rails 6.1.4.1
yarn add jquery bootstrap popper.js
だと最新になると動作しなかったので4.5.3に指定した。

#これ

yarn add jquery bootstrap@4.5.3 popper.js

image.png

完了
image.png

#config/webpack/environment.jsにコード追加
importやrequireを使わずに$やBootstrapのJavaScriptを使えるようにする

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

#app/javascript直下にstylesheets/application.scssを作成

stylesheetsというフォルダを作り、application.scssというファイルを作成でOK
image.png

あとはファイル内に

@import "~bootstrap/scss/bootstrap";

と書き込んで完了
image.png

#Bootstrapを使えるようにする
次にapp/javascript/packs/application.jsにコードを書き込む
image.png

import 'bootstrap';
import '../stylesheets/application';
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?