LoginSignup
1
1

More than 5 years have passed since last update.

ローカル環境(Ubuntu)でrails5にBootstrap4を導入しようとしてハマった件

Posted at

ローカル環境

Vagrant + Virtualbox + Ubuntu
PC: mac
ruby 2.4.1
Rails 5.1.6.1

ハマるまでの手順

実装

まずは、Gemfileに書いてインストール

gem 'bootstrap', '~> 4.1.3'
gem 'jquery-rails'
$ bundle install

コントローラーとアクション名を作成しておく

$ rails g controller top 

reset.cssを書き込むファイルreset.scssを作成して書き込む

app/stylesheets/reset.scss
/* http://meyerweb.com/eric/tools/css/reset/ 
   v2.0 | 20110126
   License: none (public domain)
*/

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
    margin: 0;
    padding: 0;
    border: 0;
    font-size: 100%;
    font: inherit;
    vertical-align: baseline; }

  /* HTML5 display-role reset for older browsers */

  article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
    display: block; }

  body {
    line-height: 1; }

  ol, ul {
    list-style: none; }

  blockquote, q {
    quotes: none; }

  blockquote {
    &:before, &:after {
      content: '';
      content: none; } }

  q {
    &:before, &:after {
      content: '';
      content: none; } }

  table {
    border-collapse: collapse;
    border-spacing: 0; }

gem関連を引っ張るために custum.scssというファイルも作成

app/stylesheets/custum.scss
@import "bootstrap";

Honokaテンプレートから検証ツールでhtmlをコピペ

日本語Bootstrapテンプレートである ほのかサイト はこちら http://honokak.osaka/
image.png

railsを起動してブラウザで確認

$ rails s -b 0.0.0.0 -p 3000

エラーメッセージが!!!!

ハマったエラーメッセージ

image.png

結論

gem 'mini_racer'

を追加したら成功!
(Live Demoボタンは後から色変えてます)

最終的に追加すべきだったのは

gem 'bootstrap', '~> 4.1.3'
gem 'jquery-rails'
gem 'mini_racer'  #これ大事!

image.png

ハマった理由の考察

同じ手順で、macOSの人はトラブルなくCSS表示された。
ということは、Ubuntuのせいか?

https://stackoverflow.com/questions/51926146/ruby-on-rails-autoprefixer-doesn-t-support-node-v4-9-1-update-it-how-to-fix
で調べると
〜〜〜〜〜〜
image.png
〜〜〜〜〜〜
というわけで、上記結論に至った。

補足:jsのファイルはどうしたかというと

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

//= require rails-ujs
//= require turbolinks
//= require_tree 
1
1
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
1