Learn How To Create A Ruby On Rails Calendar

Ruby On Rails Calendar

In this article, we are going to learn how to create a calendar with ruby on rails. Ruby on Rails already come with ready-made modules, plugins that help developers save time. Ruby On Rails is an open source framework under the MIT license that can be used to design a number of different applications. Calendar is a simple but effective app to learn RoR basics. It shows the fundamentals of the framework and also allows you to easily add your own functionality. Rails can work with multiple types of servers and database.

To start the application, you need to install rails installer on your system. You can download rails installer from http://railsinstaller.org/en and follow the instructions to install it on your system.

After completing the installation of railsinstaller, this will create sites folder on your C drive. Open the command prompt as an administrator and go to sites folder. Create an application using below command

This command will create some plugins, models, views, etc. in your application as shown below:

rails new calendar

Go to the calendar folder and run the command below to start the server

cd calendar

You will see the server will start running on localhost:3000 as shown below.
running on localhost

Open “C:\Sites\calendar\lib” location and create “calendar.rb” file. Add the code below in the calendar.rb file. Save and Close.

Now, we need to change our project from config to file auto load.rb in the lib folder. Rails doesn’t do this by default.

To modify the application config file, open “C:\Sites\calendar\config location and you will see the application.rb” file. Open the application.rb file and add the code below.

Now, let’s include bootstrap to our application. In this application, we are loading bootstrap from Yandex’s CDN. You can also apply your own stylesheet for this application. Open the application.html.erb file from the “C:\Sites\calendar\app\views\layouts” location and modify the code.

Let’s create a controller by using below rails command

create a controller

This command will generate a controller in your application. Open the “calendar_controller.rb” file in “C:\Sites\calendar\app\controllers” location and add the code below.

Now modify your routes file, which is located in your config folder. Open routers.rb file and add the code given below.

Now to create a helper method for rendering the calendar, open “calendar_helper.rb” file from C:\Sites\calendar\app\helpers folder and add the code below.

Lets open the show view file – “show.html.erb” from “C:\Sites\calendar\app\views\calendar” location for adding a calendar controller and add the code given below:

Now, go to Command prompt once again and run the server with rails command and refresh your browser. You will see the calendar below.

Calendar example

In this blog, we will learn how to design a complete calendar from scratch on Ruby on Rails. While this is an extremely basic application, you can easily add more features to improve it’s functionality.


Please enter your comment!
Please enter your name here