Tag: Rails/Bootstrap4
yarn add bootstrap jquery popper.js
require("jquery") //jQueryを追加 require("bootstrap") //Bootstrapを追加
*= require bootstrap/dist/css/bootstrap.min.css
@import "bootstrap/scss/bootstrap";
//= link_tree ../images //= link_directory ../stylesheets .css //= link_directory ../javascripts .js
const { environment } = require('@rails/webpacker') //ここから const webpack = require('webpack') environment.plugins.prepend('Provide', new webpack.ProvidePlugin({ $: 'jquery/src/jquery', jQuery: 'jquery/src/jquery' }) ) //ここまで module.exports = environment
gem 'bootstrap', '~> 4.1.1' gem 'jquery-rails'
bundle show |fgrep sprockets-rails
@import "bootstrap";
<!DOCTYPE html> <html> <head> <title>Rails5Bootstrap4Demo</title> <%= csrf_meta_tags %> <%= csp_meta_tag %> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> </head> <body> <div class="container"> <%= yield %> </div> </body> </html>
bundle exec rails g kaminari:views bootstrap4
$primary: #337ab7; @import "bootstrap"; html { font-size: 14px; /* ルート要素のフォントサイズを1rem=14pxと定義する */ }
<!-- Button trigger modal --> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-remote="true"> Launch demo modal </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <button type="button" class="btn btn-primary">Save changes</button> </div> </div> </div> </div>
//= require rails-ujs //= require jquery3 //= require popper //= require bootstrap-sprockets
<p> <%= link_to("モーダル", modal_link_books_path, {"data-toggle" => "modal", "data-target" => '#exampleModal', :remote => true}) %> </p>
<p> <%= link_to("モーダル", modal_link_books_path, {"data-toggle" => "modal", "data-target" => '#exampleModal'}) %> </p>
//= require popper //= require bootstrap-sprockets