Multiple Themes in Rails 6 Applications

This article will discuss how to implement multiple bootstrap themes in Ruby on Rails 6 applications. This article is a continuation of this article, which explains how to implement a single theme.

Assuming the admin theme is successfully integrated into your application, start working on the main application theme.

1
yarn add startbootstrap-creative

In app/assets/stylesheets/application.scss, add theme and bootstrap styles.

1
2
3
4
# app/assets/stylesheets/application.scss

@import "bootstrap/scss/bootstrap.scss";
@import "startbootstrap-creative/src/scss/styles";

In app/javascript/packs/application.js, put the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// app/javascript/packs/application.js

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")

var jQuery = require("jquery");

// import jQuery from "jquery";
global.$ = global.jQuery = jQuery;
window.$ = window.jQuery = jQuery;

require("bootstrap");
require("startbootstrap-creative/src/js/scripts");

In app/javascript/packs/application.js, put the following code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# app/javascript/packs/application.js

<!DOCTYPE html>
<html>
 <head>
   <title>MultipleBootstrapThemes</title>
   <%= csrf_meta_tags %>
   <%= csp_meta_tag %>

   <!-- Font Awesome icons (free version)-->
   <script src="https://use.fontawesome.com/releases/v5.13.0/js/all.js" crossorigin="anonymous"></script>
   <!-- Google fonts-->
   <link href="https://fonts.googleapis.com/css?family=Merriweather+Sans:400,700" rel="stylesheet" />
   <link href="https://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic" rel="stylesheet" type="text/css" />
   <!-- Third party plugin CSS-->
   <link href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css" rel="stylesheet" />

   <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
   <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
 </head>

 <body>
   <%= yield %>
 </body>
</html>

Now in app/views/welcome/index.html.erb, put the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# app/views/welcome/index.html.erb

<nav class="navbar navbar-expand-lg navbar-light fixed-top py-3" id="mainNav">
 <div class="container">
   <a class="navbar-brand js-scroll-trigger" href="#page-top">Start Bootstrap</a>
   <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
   <div class="collapse navbar-collapse" id="navbarResponsive">
     <ul class="navbar-nav ml-auto my-2 my-lg-0">
       <li class="nav-item"><a class="nav-link js-scroll-trigger" href="#about">About</a></li>
       <li class="nav-item"><a class="nav-link js-scroll-trigger" href="#services">Services</a></li>
       <li class="nav-item"><a class="nav-link js-scroll-trigger" href="#portfolio">Portfolio</a></li>
       <li class="nav-item"><a class="nav-link js-scroll-trigger" href="#contact">Contact</a></li>
     </ul>
   </div>
 </div>
</nav>
<!-- Masthead-->
<header class="masthead">
 <div class="container h-100">
   <div class="row h-100 align-items-center justify-content-center text-center">
     <div class="col-lg-10 align-self-end">
       <h1 class="text-uppercase text-white font-weight-bold">Your Favorite Source of Free Bootstrap Themes</h1>
       <hr class="divider my-4" />
     </div>
     <div class="col-lg-8 align-self-baseline">
       <p class="text-white-75 font-weight-light mb-5">Start Bootstrap can help you build better websites using the Bootstrap framework! Just download a theme and start customizing, no strings attached!</p>
       <a class="btn btn-default btn-xl js-scroll-trigger" href="#about">Find Out More</a>
     </div>
   </div>
 </div>
</header>
<!-- About-->
<section class="page-section bg-purple-1" id="about">
 <div class="container">
   <div class="row justify-content-center">
     <div class="col-lg-8 text-center">
       <h2 class="text-white mt-0">We've got what you need!</h2>
       <hr class="divider light my-4" />
       <p class="text-white-50 mb-4">Start Bootstrap has everything you need to get your new website up and running in no time! Choose one of our open source, free to download, and easy to use themes! No strings attached!</p>
       <a class="btn btn-light btn-xl js-scroll-trigger" href="#services">Get Started!</a>
     </div>
   </div>
 </div>
</section>
<!-- Services-->
<section class="page-section" id="services">
 <div class="container">
   <h2 class="text-center mt-0">At Your Service</h2>
   <hr class="divider my-4" />
   <div class="row">
     <div class="col-lg-3 col-md-6 text-center">
       <div class="mt-5">
         <i class="fas fa-4x fa-gem text-purple-1 mb-4"></i>
         <h3 class="h4 mb-2">Sturdy Themes</h3>
         <p class="text-muted mb-0">Our themes are updated regularly to keep them bug free!</p>
       </div>
     </div>
     <div class="col-lg-3 col-md-6 text-center">
       <div class="mt-5">
         <i class="fas fa-4x fa-laptop-code text-purple-1 mb-4"></i>
         <h3 class="h4 mb-2">Up to Date</h3>
         <p class="text-muted mb-0">All dependencies are kept current to keep things fresh.</p>
       </div>
     </div>
     <div class="col-lg-3 col-md-6 text-center">
       <div class="mt-5">
         <i class="fas fa-4x fa-globe text-purple-1 mb-4"></i>
         <h3 class="h4 mb-2">Ready to Publish</h3>
         <p class="text-muted mb-0">You can use this design as is, or you can make changes!</p>
       </div>
     </div>
     <div class="col-lg-3 col-md-6 text-center">
       <div class="mt-5">
         <i class="fas fa-4x fa-heart text-purple-1 mb-4"></i>
         <h3 class="h4 mb-2">Made with Love</h3>
         <p class="text-muted mb-0">Is it really open source if it's not made with love?</p>
       </div>
     </div>
   </div>
 </div>
</section>
<!-- Portfolio-->
<div id="portfolio">
 <div class="container-fluid p-0">
   <div class="row no-gutters">
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/1.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/1.jpg" alt="" />
         <div class="portfolio-box-caption">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/2.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/2.jpg" alt="" />
         <div class="portfolio-box-caption">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/3.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/3.jpg" alt="" />
         <div class="portfolio-box-caption">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/4.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/4.jpg" alt="" />
         <div class="portfolio-box-caption">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/5.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/5.jpg" alt="" />
         <div class="portfolio-box-caption">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
     <div class="col-lg-4 col-sm-6">
       <a class="portfolio-box" href="assets/img/portfolio/fullsize/6.jpg">
         <img class="img-fluid" src="assets/img/portfolio/thumbnails/6.jpg" alt="" />
         <div class="portfolio-box-caption p-3">
           <div class="project-category text-white-50">Category</div>
           <div class="project-name">Project Name</div>
         </div>
       </a>
     </div>
   </div>
 </div>
</div>
<!-- Call to action-->
<section class="page-section bg-dark text-white">
 <div class="container text-center">
   <h2 class="mb-4">Free Download at Start Bootstrap!</h2>
   <a class="btn btn-light btn-xl" href="https://startbootstrap.com/themes/creative/">Download Now!</a>
 </div>
</section>
<!-- Contact-->
<section class="page-section" id="contact">
 <div class="container">
   <div class="row justify-content-center">
     <div class="col-lg-8 text-center">
       <h2 class="mt-0">Let's Get In Touch!</h2>
       <hr class="divider my-4" />
       <p class="text-muted mb-5">Ready to start your next project with us? Give us a call or send us an email and we will get back to you as soon as possible!</p>
     </div>
   </div>
   <div class="row">
     <div class="col-lg-4 ml-auto text-center mb-5 mb-lg-0">
       <i class="fas fa-phone fa-3x mb-3 text-muted"></i>
       <div>+1 (555) 123-4567</div>
     </div>
     <div class="col-lg-4 mr-auto text-center">
       <i class="fas fa-envelope fa-3x mb-3 text-muted"></i>
       <!-- Make sure to change the email address in BOTH the anchor text and the link target below!-->
       <a class="d-block" href="mailto:contact@yourwebsite.com">contact@yourwebsite.com</a>
     </div>
   </div>
 </div>
</section>
<!-- Footer-->
<footer class="bg-light py-5">
 <div class="container"><div class="small text-center text-muted">Copyright © 2020 - Start Bootstrap</div></div>
</footer>

Now two bootstrap themes have been successfully integrated. Happy styling!