Sample Project in Ruby On Rails

Please visit my website and subscribe to my youtube channel for more articles

https://devops4solutions.com/

In this blog , we will create a sample project (create and read operation) of Ruby on Rails project

Introduction

Ruby on Rails (or just “Rails” for short) is a web development framework written in the Ruby programming language. Rails is used by companies as diverse as Airbnb, Basecamp, Disney, GitHub, Hulu, Kickstarter, Shopify, Twitter, and the Yellow Pages.

What makes Rails so great?

Firstly, Ruby on Rails is 100% open-source.Rails effectively creates a domain-specific language for writing web applications. As a consequence, many common web programming tasks — such as generating HTML, making data models, and routing URLs — are easy with Rails, and the resulting application code is concise and readable.

Prerequisite

To develop a web application using Ruby on Rails Framework, you need to install the following software −

  • Ruby
  • The Rails Framework
  • A Web Server
  • A Database System

Please visit Ruby on Rail Installation link.

Ruby on Rails MVC Framework

The Model View Controller principle divides the work of an application into three separate but closely cooperative subsystems.

Model (ActiveRecord )

It maintains the relationship between the objects and the database and handles validation, association, transactions, and more.

View ( ActionView )

It is a presentation of data in a particular format, triggered by a controller’s decision to present the data. They are script-based template systems like JSP, ASP, PHP, and very easy to integrate with AJAX technology.

Controller ( ActionController )

The facility within the application that directs traffic, on the one hand, querying the models for specific data, and on the other hand, organizing that data (searching, sorting, messaging it) into a form that fits the needs of a given view.

Rails application structure has an application directory called app/ containing three subdirectories: models, views, and controllers. This is a hint that Rails follows the model-view-controller (MVC) architectural pattern, which enforces a separation between the data in the application (such as user information) and the code used to display it, which is a common way of structuring a graphical user interface (GUI).

When interacting with a Rails application, a browser sends a request that is received by a webserver and passed on to a Rails controller, which is in charge of what to do next. In some cases, the controller will immediately render a view, which is a template that gets converted to HTML and sent back to the browser. More commonly for dynamic sites, the controller interacts with a model, which is a Ruby object that represents an element of the site (such as a user) and is in charge of communicating with the database. After invoking the model, the controller then renders the view and returns the complete web page to the browser as HTML.

Create a Sample Project

This will create a Rails application called Blog in a blog directory and install the gem dependencies that are already mentioned in Gemfile using bundle install.

rails new blog
Image for post
Image for post
Image for post
Image for post

Directory structure of rails project as shown below:

Image for post
Image for post
Rails Directory Structure

Starting WebServer

cd blog
bin/rails server
Image for post
Image for post

Open web browser : http://localhost:3000

Image for post
Image for post

If you will get the above page , it means whole setup is completed successfully for the Ruby on Rails project.

Now you can customize the code and create any sample application as per your need. I have created a basic (Create and Read Operation) on Ruby On Rails. Please refer the github link for Ruby on Rails Sample Project.

To understand how the sample project is being created, please refer this link

Finally congratulations!! You have successfully followed each and every step for creating Sample Project in Ruby On Rails.

References:

I do not own 100% of this content. I have referred multiple websites and books to learn and produce this content. I give full credit to those websites and books for the content.

Written by

Devops Automation Enginneer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store