How to deploy Bootstrap on Rails

How to deploy Bootstrap in Ruby

procedure

Install Bootstrap with gem

Gemfile


gem 'bootstrap', '~> 4.3.1'
gem 'jquery-rails'

Terminal


bundle install

Create SCSS file

Terminal


mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss

app/assets/stylesheets/application.scss


/*
 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 *
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 *
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.
 *
 *= require_tree .<(Deleted)
 *= require_self <(deleted)
 */
@import "bootstrap";<(Addition)

Modify JS file

app/assets/javascripts/application.js


#Added the following three
//= require jquery3
//= require popper
//= require bootstrap

#Original code
//= require rails-ujs
//= require activestorage
//= require turbolinks

Restart Rails (Puma)

Dockerfile


#Install the required packages for Rails
RUN apt-get update -qq && apt-get install -y nodejs
RUN curl -sL https://deb.nodesource.com/setup_10.x | bash - \
    && apt-get install -y nodejs

#In the description of the official website below, node.The version of js is low and bootstrap cannot be used
# RUN apt-get update -qq && apt-get install -y nodejs

How to use Bootstrap (template)

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


<!DOCTYPE html>
<html>
  <head>
    <title>App</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="d-flex flex-column flex-md-row align-items-center p-3 px-md-4 mb-3 bg-white border-bottom shadow-sm">
      <h5 class="my-0 mr-md-auto font-weight-normal">Company name</h5>
      <nav class="my-2 my-md-0 mr-md-3">
        <a class="p-2 text-dark" href="#">Features</a>
        <a class="p-2 text-dark" href="#">Enterprise</a>
        <a class="p-2 text-dark" href="#">Support</a>
        <a class="p-2 text-dark" href="#">Pricing</a>
      </nav>
      <a class="btn btn-outline-primary" href="#">Sign up</a>
    </div>
    <p class="notice"><%= notice %></p>
    <p class="alert"><%= alert %></p>
    <%= yield %>
  </body>
</html>

It will be like this!

e8cf55d4ebff169216236d8d3dfac518.png

That's all from the scene!

Recommended Posts

How to deploy Bootstrap on Rails
How to deploy jQuery on Rails
How to deploy on heroku
[Ruby on Rails] How to install Bootstrap in Rails
How to deploy Laravel on CentOS 7
How to use Ruby on Rails
How to deploy
Rails on Tiles (how to write)
Deploy Rails on Docker to heroku
How to deploy a Rails application on AWS (article summary)
[Ruby on Rails] How to use CarrierWave
Deploy to Heroku [Ruby on Rails] Beginner
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to write Rails
Introducing Bootstrap to Rails 5
Introducing Bootstrap to Rails !!
How to adapt Bootstrap
Deploy RAILS on EC2
How to uninstall Rails
Deploy to Ruby on Rails Elastic beanstalk (EB deploy)
[Ruby on Rails] How to display error messages
How to deploy a container on AWS Lambda
How to add / remove Ruby on Rails columns
[Rails MySQL] How to reset DB on heroku
[Ruby on Rails] How to use session method
[rails] How to post images
[Rails] How to use enum
[Rails] How to install devise
[Rails] How to use enum
How to read rails routes
How to use rails join
How to terminate rails server
How to write Rails validation
How to write Rails seed
[Rails] How to use validation
[Rails] How to disable turbolinks
[Rails] How to use authenticate_user!
[Rails] How to use "kaminari"
[Rails] How to implement scraping
[Rails] How to make seed
How to write Rails routing
[Rails] How to install simple_calendar
[Rails] How to install reCAPTCHA
[Rails] How to use Scope
[Ruby on Rails] How to write enum in Japanese
[Ruby on Rails] How to change the column name
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
[Ruby On Rails] How to reset DB in Heroku
(Ruby on Rails6) How to create models and tables
[Rails] How to use gem "devise"
[Rails] How to install Font Awesome
Deploy to Ruby on Rails Elastic beanstalk (IAM permission change)
[Rails] How to use flash messages
[rails] How to display db information
[Rails] How to write in Japanese
[Rails] How to prevent screen transition
[Java] How to update Java on Windows
How to install ImageMagick on Windows 10
How to deploy a simple Java Servlet app on Heroku
How to run JavaFX on Docker