Rails is not a programming language. It’s an open source framework which is used for building powerful web applications. Ruby On Rails Framework is built on the ruby programming language. The new version of bootstrap, Bootstrap 4, doesn’t have a Ruby Gem preinstalled in the system . In this article, I am going to help you learn how to install bootstrap 4 on Ruby On Rails. To install bootstrap, first you need to download the railsinstaller from http://railsinstaller.org/en and install it in your machine. We are using the link below to install bootstrap 4 on Ruby On Rails.
To start the project you need to install Node and run a few lines of code on the command line.
1) You can download Node JS from https://nodejs.org
2) Install grunt-cli by using the code below on the command prompt
npm install -g grunt-cli
3) Open a command prompt and run this command:
gem install bundler
Now, lets get started with our Rails Application. Open a command prompt as an administrator and go to sites folder to create a rails app.run command with the name “bootstrap4example”
” rails new bootstrap4example ”
Go to the bootstrap4example folder and run command below to run a project named ” rails s ”
The project will run on the localhost http://localhost:3000/ as seen belowL
Let’s add bootstrap to your Gemfile.
Import the bootstrap styles in the application.scss file which is placed in the “app/assets/stylesheets” folder. If you have already generated a new Rails app, it will be come with a .css file. So, rename the C:\Sites\bootstrap4example\app\assets\stylesheets\application.css file with “.scss”extension (for Sass syntax).
Add @import “bootstrap”; in the application.scss file as given below
Run ” bundle install “ on the command prompt and restart the server.
Let’s create a static page controller by using the command given:
“ rails generate controller Pages index “
Go to the ” C:\Sites\bootstrap4example\config\routes.rb file “ and add the code given below.
Add the code in the image below to your “C:\Sites\bootstrap4example\app\views\pages\index.html.erb” file.
Add the below code in your bootstrap 4 “C:\Sites\bootstrap4example\app\views\layouts\application.html.erb” file
Restart the server by using the command given below and you will see that you have successfully installed Bootstrap on your Ruby On Rails.
Source Code for this installation of Bootstrap on RoR