Giter VIP home page Giter VIP logo

bootstrap-rails6's Introduction

README

Sample app to add Bootstrap 5, JavaScript and Images to Rails 6.1 App

Version

  • ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
  • Rails 6.1.4
  • Bootstrap 5.0.2

Instructions

  1. In application.html.erb change to stylesheet_pack_tag as shown:
<%= stylesheet_pack_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
  1. Create new files/folders in app/javascript:
app/javascript
└───images
│       test.jpg
│
└───packs
│       application.js # already exists
│       application.scss
│
└───src
│       my_script.js
│
└───stylesheets
        my_styles.scss
$ touch packs/application.scss
$ mkdir -p src && touch src/my_script.js
$ mkdir -p stylesheets && touch stylesheets/my_styles.scss
$ mkdir -p images && wget -O images/test.jpg http://lorempixel.com/640/480/
  1. Add Bootstrap and Popper JS to app
$ yarn add bootstrap
$ yarn add @popperjs/core
  1. Include Bootstrap in application.js file:
require.context("../images", true)
import "bootstrap"
import "@popperjs/core"
import "../src/my_script.js"

Include Bootstrap in application.scss file:

@import "~bootstrap/scss/bootstrap.scss";
@import "../stylesheets/my_styles.scss"
  1. Create home controller with index action
$ rails g controller home index
  1. Add Bootstrap modal component in app/views/home/index.html.erb
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
  1. Add Image tag in app/views/home/index.html.erb
<br>
<%= image_pack_tag("media/images/test.jpg") %>

bootstrap-rails6's People

Contributors

overdrivemachines avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.