As we know that in almost all web applications there is a set of code which has to be executed often in many places.
Now suppose we have a header and footer which has to be used all over the project.
Now if we would write this code of header and footer in all the pages, it would be wastage of memory and nothing else.
This will also affect the time and space complexity of the project.
Now to avoid this kind of situation what we can do is write the code of header and footer in separate files and then include these files in the application.html.erb file so that the code would be reflected in all the pages, as the code written in application.html.erb file is executed first before any other view file.
These partials are kept in layouts folder of the project and then they can be included by their name in the application.html.erb file.
Below is a demonstration on how to use partials in your rails application.
Firstly we need to create a file in views/layouts/_header.html.erb like this
<nav class="navbar navbar-inverse" style="margin-top:-50px;">
<h1>This is the header!</h1>
now same way we need to create a file in views/layouts/_footer.html.erb
<footer class="panel-footer" style="background: #8F9284;">
<h4 style="text-align: center;color: white;">
copyright @ Chayan Sharma. All rights reserved.
Once done with this now all we are left with is including these files in the views/layouts/application.html.erb file like this