Ruby on Rails Introduction (original) (raw)

Last Updated : 30 Aug, 2024

Ruby on Rails or also known as rails is a server-side web application development framework that is written in the Ruby programming language, and it is developed by David Heinemeier Hansson under the MIT License. It supports MVC(model-view-controller) architecture that provides a default structure for database, web pages, and web services, it also uses web standards like JSON or XML for transfer data and HTML, CSS, and JavaScript for the user interface. It emphasizes the use of other well-known software engineering pattern and paradigms like:

Ruby on Rails was first released in July 2004 but until February 2005 did not share the commit rights. In August 2006, it would ship Ruby on Rails with Mac OS X v10.5 "Leopard". Ruby on Rail's latest version(Rail 5.0.1) released on December 21, 2016. Action cable, Turbolinks 5, and API mode Introduced in this version.

**Why Ruby on Rails?

**Where to use Ruby on Rails?

You can use Ruby on Rails application in various area of web development like in a long term project which needs large transformation, or in the project that has heavy traffic, or to develop a short prototype or MVPs, or in a project that requires wide range of complex functions, etc.

Feature of Ruby on Rails

As we know that most of the languages like Java, HTML, CSS, etc. do not cover the front end and back end. They either only for the back end or for the front end but Ruby on Rails is used for both front end back end, it is like a complete package to develop a web application. Some important features of Ruby on Rails are:

Rails-MVC-Architecture

Model-view-controller Architecture

**for more: **Features of Ruby on Rails

Advantages of Ruby on Rails

Disadvantages of Ruby on Rails

**Example:

To create a rails application you need to follow the following steps:

**Step 1: Open a terminal and write the following command. This command creates an application with the name 'myFirstProject'.

rails new myFirstProject

**Step 2: Now we move into our application directory.

cd myFirstProject

Here, myFirstProject contains these files.

**Step 3: Now we create a rails server using the following command.

bin/rails s

or

bin/rails server

By default, the rails server uses port 3000. If you want to change the port number we can use the following command:

rails server -p portNumber

Now open the browser and open http://localhost:3000/. If your server works properly then you will get this page.

**Step 4: Open another terminal and move to myFirstProject directory. Now we create a controller named 'sample' for our home page.

rails generate controller sample

**Step 5: Now we add an index page. So open sublime text and write the following HTML code and save the file with name index.html.erb, and in location: /myFirstProject/app/views/sample/index.html.erb.

My first ruby on rails application

**Step 6: After creating index page, we need to route the ruby on rails to this page. So for that open routes.rb file which is present in location: /myFirstProject/config/routes.rb. Now write the following line in the routes.rb file

root'sample#index'

**Step 7: Now refresh the browser window to see the final output.