Download as pdf or txt
Download as pdf or txt
You are on page 1of 32

See discussions, stats, and author profiles for this publication at: https://www.researchgate.

net/publication/322222154

An Introduction to Ruby Programming Language

Presentation · November 2016


DOI: 10.13140/RG.2.2.13384.62720

CITATION READS

1 5,102

1 author:

Ali Tourani
University of Guilan
22 PUBLICATIONS   56 CITATIONS   

SEE PROFILE

Some of the authors of this publication are also working on these related projects:

Search Engine View project

Vehicle Speed Measurement using Video Processing View project

All content following this page was uploaded by Ali Tourani on 03 January 2018.

The user has requested enhancement of the downloaded file.


a.tourani1991@gmail.com
• Overview
• Ruby on Rails!
• How to Install?
• Creating a project
• Active Records
• Migration
• Conclusion
• References
• An Object-Oriented programming language
• Released in 1995 by Yukihiro Matsumoto
• Influenced by Perl, Smalltalk, Eiffel, Ada, and Lisp
• Similar to Smalltalk, Perl and Python
• A Server-Side Scripting Language (like Python and Perl)
• Open-Source, Free and General-Purpose!
• Easy connection to DB2
• Easy connection to MySQL
• Easy connection to Oracle
• Easy connection to Sybase
• Easy to write Common Gateway Interface (CGI) scripts
• Executable programs running on a server that generate web pages dynamically
• Easy to develop internet applications
• Easy to maintain big programs written in Ruby (Scalability)
• Rails: an Open-Source Web application framework
• Written in Ruby by David H. Hansson
• Released in 2005
• Designed to make programming web applications easier by
making assumptions about what every developer needs
• Fast and Easy Development
• MVC Based Framework
What is it?!
• Basic Web Architecture:
• Data Fetching and Data Processes combined in one form
• Direct access to data
• Security problems
• Hard to change for programmers (get access to unread data)

Browser Web Page Database


• MVC (Model-View-Controller) Web Architecture:
• Multiple Layers
• Providing GUI for user
• Encapsulation of Data/Licenses/Validation Checks from End-User
Browser Controller

View Model Database


• MVC (Model-View-Controller) Web Architecture:
Browser Controller

View Model Database

Data Validation Communication


Check with data
• MVC (Model-View-Controller) Web Architecture:
Browser Controller

Communication
with End User

No Data
Validation Check View Model Database
• MVC (Model-View-Controller) Web Architecture:
Browser Controller Interface for View
and Model Parts

View Model Database


• MVC (Model-View-Controller) Web Architecture:

Browser Controller

View Model Database


• Rails Architecture (Based on MVC):
Rails Framework
Browser Web Server Public

Routing

Controller

View Model Database


• How Ruby Works with Databases:
• Using GEM files (Ruby Libraries)
• Supported: MySQL, Oracle, Neo4J, DB2, SQLite, ODBC, ….

DBD::Oracle

API DBI DBD::MySQL

DBD: Neo4J
Application
Ruby Script Programming Database Interface Database Description Databases
Interface
Hulu Github Yellow Pages

Twitter Slide Share Base Camp Shopify


http://rubyinstaller.org/downloads/
(Newest: 2.3.1)

C:\> cd DevKit
C:\ DevKit > ruby dk.rb init
C:\ DevKit > ruby dk.rb install
Gem install Rails
Gem install MySQL2
with-MySQL-include=“C:\MySQL Server 5.6\lib\
with-MySQL-include=“C:\MySQL Server 5.6\include\
http://www.railsinstaller.org/en
rails new project name

• Let’s Try!
• Creating/Opening a project
• Downloading necessary GEM files
• Starting PUMA Web Server
• Showing Smoke test page

• A Hello World Application?!


Browser Controller

• A “Hello World” Application:


View Model Database

• Controller
• View

• Open View in Editor and … <h1>Hello World!</h1>


Browser Controller

• A “Hello World” Application:


View Model Database

Note: Some Problems in Windows

• http://localhost:3000/
get access M in MVC
database/view class
record object

a lot of Very little


configuration code configuration code
• Goal: find out how the mapping between models and database tables

• Database Table
• Model Class
• Foreign keys
• Primary keys
subclass the ApplicationRecord class
Map SQL Table to a Model
User (Model)

• Create: Name Occupation

create and save a new record into the database

object can be instantiated without being saved


needs user.save to commit the record to database

yield the new object to a block for initialization


User (Model)

• Read: Name Occupation

return a collection with all users

return the first user

return the first user named David

find all users named David who are Code Artists and
sort by created_at in reverse chronological order
User (Model)

• Update: Name Occupation

modify attributes and save to the database

a hash mapping attribute names to the desired value

updating several attributes at once


User (Model)

• Delete: Name Occupation

Remove object from the database


Up (Update to new state) Down (Rollback to previous state)

database schema
codes and instructions
share
• https://www.ruby-lang.org/en/
• https://www.railstutorial.org/
• http://guides.rubyonrails.org/

View publication stats

You might also like