top of page

Ruby on Rail

What is Ruby?

  • Ruby is a high-level interpreted programming language.

  • It's an object-oriented program.

  • It is open-source on web.

History

  • It was created in 1995.

  • Developed by  Yukihiro Matsumoto in Japan.

Features

  • Ruby is a general-purpose programming language.

  • Ruby can easily be connected to DB2, MySQL, Oracle, and Sybase.

  • Ruby can embed to the HTML page.

  • Has rich libraries.

  • Cross-platform.

Ruby Installation

  • We can download the Ruby installer from its official site, https://www.ruby-lang.org/en/downloads/

  • Choose your OS and click on download button.

  • It contains Ruby language, an execution environment, documentation, developer kit & more.

Screenshot_1.jpg
  • Open the .exe installer file.

  • Make sure you tick the "Add Python 3. to PATH" checkbox and click on "Install Now", 

Screenshot_1.jpg
  • We wrote the Hello World program in ruby.

  • Saved as HelloRuby.rb file name.

  • We can execute the Ruby file on command prompt by typing ruby HelloRuby.rb

  • But we build the enviroment for the Sublime Text editor for Ruby.

  • By pressing Ctrl + B, we got the result.

Screenshot_1.jpg

What is Ruby on Rails?

  • Is a server-side web application development framework.

  • Written in Ruby.

  • It supports MVC pattern to create web application.

History

  • Written by David Heinemeier Hansson.

  • In 2005.

Features

  • It is an open source Ruby framework for developing database-backed web applications.

  • Can write 10 times faster than Java Framework.

  • No compilation is required.

  • There is 2 guiding principle:

Ruby on Rails Principles:

Don't Repeat Yourself

(DRY)

  • Every code must have an unambiguous, single representation within the system.

  • A code will not repeat again.

 

Convention Over Configuration

(CoC)

  • It provides a different best way to do many things in a web application.

 

Ruby on Rail Environment

  • To develop a web-application environment, we need to have following installed on computer.:

    • Ruby

    • Ruby on Rails Framework

    • Database (MySQL)

    • Web Server (WEBrick)

Installing Ruby 

  • We already installed Ruby in previous step.

Installing Rails

  • In Command Prompt, We can install Rails & its dependencies using the following command; gem intall rails

  • You need an internet connection for installing.

Screenshot_2.jpg

To install Rails

To check gem version

  • Type rails -v to check the Rails version.

Screenshot_3.jpg

To check Rails version

Installing Server

  • We can verify the Ruby on Rail installation.

  • To create a StoneProfits project rails new StoneProfits

Screenshot_5.jpg

To create a project

  • The new project is createcd on C:\Users\SPS\StonProfits 

  • Open the Command prompt on that directory.

  • To run WEBrick web server on our PC, type cd StoneProfits > rails server

Screenshot_7.jpg

To navigate our project folder

To run on WEBrick server

  • We can check the server on the browser by going localhost:3000

Screenshot_6.jpg

Installing Database

  • We have installed MySQL RDBMS for the database.

  • To install PostgreSQL, type gem install postgre

Screenshot_2.jpg

To install PostgreSQL database

Rails on MVC 

  • Rails web application works on MVC.

  • Model, View & Controller are associated with some folder on local Ruby directory as ActiveRecord, ActionView & ActionController.​

MVC

computer-monitor-icon-46238.png

Controller

  • It directs the traffic.

  • Querying the models for data.

  • Organizing that data

View

It is a presentation of data triggered by Controller. (AJAX, etc)

 

Model

Maintains relation between objects and the database and handles validation, 

 

database-logo.png

Creating Rails Web Application

  • Rails is a framework and set of helper scripts.

  • To start our Library System application, type rails new library on CMD.

Screenshot_1.jpg

The Hello World

  • Python is an interpreted programming language.

  • We need to write Python (.py) files in a text editor and then put those files into the python interpreter to be executed.

  • Where HelloWorld.py is the name of your python file.

  • We wrote the one line program in a text editor.

bottom of page