Table of contents
1.
Introduction
1.1.
Prerequisites
2.
Why ruby on rails? 
2.1.
Features
3.
Setting up the ruby server
3.1.
Installing Ruby
4.
Frequently Asked Questions
5.
Key Takeaway
Last Updated: Mar 27, 2024

Introduction to Ruby on Rails

Author Aditya Kumar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

David Heinemeier Hansson developed ruby on Rails under the MIT license. It uses Model View Controller(MVC) architecture, providing a structure for databases, web pages and web services. JSON(Javascript Object Notation) and XML(Extensible Markup Language) structures are used to transfer data from front to back and vice versa. Rails was designed to give the developer a more productive environment.

Suppose we need to take and maintain a database in our application. Rails is just another alternative for it.

Prerequisites

General understanding of Object-oriented programming is a must, along with basic knowledge of web development. 

Why ruby on rails? 

Ruby on rails is time-efficient as it greatly increases the productivity of a developer and it has a larger community. The codebase is easy to maintain. Rails provide a number of tools and libraries. All this increases the performance of the codebase. Rails is generally used in large projects that are to be scaled and is more time taking. More points can be considered as  discussed below:

  • Being a full-stack framework, it has everything we need to build any database-related web application
  • We can access its code as it is open source.
  • Ruby as a language is easy to learn, has a large community of developers, is object-oriented and has a very extensive library.
  • Rails provide testing features and have libraries that one can extend to customize the test cases using fixtures and harnesses. Automated tests can then be executed using the rake utility.
  • Rails provide development, production and test environment which helps in development processes. For example, rails create a fresh temporary database every time the test is executed.

Features

  • Convention over configuration: In rails, one can modify the general conventions of the application giving more flexibility to the programmer. 
  • Metaprogramming: Rails supports metaprogramming in which one can modify classes and functions at runtime.
  • Active records: Rails provide active records which are handling data over in the application. It enables interaction of the database layer with the view.

Setting up the ruby server

Let us create a ruby on rails project. But before that, we will need to install certain dependencies. 

Installing Ruby

sudo apt-get install ruby-full  (on linux debian based)

https://rubyinstaller.org/ (on windows download the installer)

Check the ruby version: ruby –version

We’ll use the sqlite3 database, so install it from the official website and check its version :

sqlite3 –version

Additionally, install nodejs from their website and confirm its version

Finally, install rails using “gem install rails” and verify its the version using “rails –version

We have now installed all required dependencies. To create a new project type in: 

rails  newProject

This will create a new directory named “newProject”

                   Source: Folder structure in rails

Enter the directory with the command “cd newProject

Now in order to start the server: 

bin/rails server

The server will then be exposed to http://localhost:3000

Output

Frequently Asked Questions

 

1.What is rails?

Ans:It is a full-stack framework that includes everything to create a database-driven application. Rails is at least ten times faster than a Java built web app. Rails is a shorthand for Ruby on rails. Ruby is a programming language used.

 

2.What is MVC architecture?

Ans: The MVC pattern is an architectural pattern used in building complex web apps. This pattern separates application logic into three logical components, the model view and controller. The model is the data-related information, the view is what is rendered onto the screen, and the controller is what controls the application view. Controllers manipulate the data coming from the model to be rendered onto the view. It acts as an interface between them.

Key Takeaway

Congratulations on getting through this article. We went through what is ruby and ruby on rails. Why do we use it? Also, we set up the rails project after installing the dependencies required. We saw the folder structure that ruby on rails follows, and understood each of them. This article will get you a quick start in ruby on rails.

If you want to learn more about ruby on rails then you can check our archives blog on ruby where you’ll find many more interesting articles.

Happy learning!

Live masterclass