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 5 years have passed since last update.

RailsにBootstrapを導入する

Posted at

記事はたくさんあるのに、どの記事も微妙に書かれていることが違ったりして割とハマったので、自分がうまく行った方法をメモ。

Rails:5.2.4
Ruby:2.6.5

gemを入れる

bootstrapjquery-railsの2つのgemを導入します。

Gemfile
gem 'bootstrap'
gem 'jquery-rails'
$ bundle install

application.scssを編集

まず、app/assets/stylesheets/application.cssの拡張子をscssに変更します。

次にファイル内の以下の2行を削除します。

app/assets/stylesheets/application.scss
*= require_tree
*= require_self

最後に、以下の記述を書き込みます。

app/assets/stylesheets/application.scss
@import "bootstrap";

application.jsを編集

app/assets/javascripts/application.jsに以下の内容を追記します。

app/assets/javascripts/application.js
//= require jquery3
//= require popper
//= require bootstrap-sprockets

設定は以上になります。
AssetPilelineの仕組みがいまいちわかっていないので、今後調べて行こうと思います。

参考

BootstrapをRailsに導入してみよう!徹底解説!
Rails 使用するCSSを指定する

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?