24-10-2016, 12:49 PM
1460803833-ROR.ppt (Size: 978.5 KB / Downloads: 6)
What is Ruby?
Ruby is a pure object-oriented programming language with a super clean syntax that makes programming simple.
In Ruby, everything is an object
Ruby is an interpreted scripting language, just like Perl, Python and PHP.
Ruby originated in Japan in 1993 by Yukihiro “matz” Matsumoto, and has started to become popular worldwide in the past few years.
Ruby is a metaprogramming language. Metaprogramming is a means of writing software programs that write or manipulate other programs thereby making coding faster and more reliable.
Why Ruby?
Ruby originated in Japan and now it is gaining popularity in US and Europe as well. The following factors contribute towards its popularity −
Easy to learn
Open source (very liberal license)
Rich libraries
Very easy to extend
Fully object-oriented
Less coding with fewer bugs
Helpful community
What is Rails?Ruby on Rails or just Rails (RoR)
Rails is an open source Ruby framework for developing database-backed web applications.
Created by David Heinemeier Hansson
Everything in Rails (templates to control flow to business logic) is written in Ruby
Rails can build the skeleton of an application, including the database tables, in just a few command
Why Rail?
All layers in Rails are built to work together so you Don’t Repeat Yourself and can use a single language from top to bottom.
An extremely productive web-application framework.
You could develop a web application at least ten times faster with Rails than you could with a typical Java framework.
Configure your code with Database Schema.
No compilation phase required
Some Differences
Javascript--born of the competition between two companies
PHP--created by a varied community
Ruby--the vision of a single person
Rails--the vision of another single person
When you compare these, you can see how the starting point influences the process of development
Some Important differences
Unlike PHP, scope in variables is defined by the leading sigil
the $ sign denotes global scope, not a variable
an @ represents local scope within an object instance
@@ represents local scope within a class
A capitalized name is a constant
Features Of ROR
Session Controler
Login Form
Security & Proper Authentication
Database Maintence
User Microposts
Current Scenario
In present scenario most of startup choose ruby on rials
According AngelList job board:
Full Time, Full Stack jobs, 968 startups Out of those: - 289 has the Ruby on Rails skill listed -244 had Python - 185 had Angular.js
- 477 Others(Basicaly JavaScript & Others)
Rails Architecture
Rails applications are implemented using the Model-View-Controller (MVC)
Model
View
Controller
Model View Controller (MVC)
Layering again
MVC allows a project team to work on different aspects of the application without stepping on each other's toes quite so often
Note that neither PHP nor Javascript encourage this, but it can be done in PHP (not so much in Javascript)
Rails enforces MVC
Model
Active Record
Model encapsulates data that the application manipulates, plus domain-specific logic
Model
Contains the data of the application
Transient
Stored (eg Database)
Enforces "business" rules of the application
Attributes
Work flow
Views
Action View
View is a rendering of the model into the user interface
Views
Provides the user interface
Dynamic content rendered through templates
Three major types
Ruby code in erb (embedded ruby) templates
xml.builder templates
rjs templates (for javascript, and thus ajax)
Controllers
Perform the bulk of the heavy lifting
Handles web requests
Maintains session state
Performs caching
Manages helper modules
Controllers
Action Controller
Controller responds to events from the interface and causes actions to be performed on the model.
Web Application
You can easily make your own web application
Goto cloud 9
Bit bucket
Gethub
How to install?
Linux and windows just overview
Playing on the Command Line
Ruby is an interpreter, just like php or bash:Avatar:~ hays$ rubyprint "howdy world!"^d
Or, use ruby -e "command":ruby -e 'puts "hello\n"'
Or, you can just use irb, which is easier:Avatar:~ hays$ irb>> print "howdy world!"howdy world!=> nil>>
Object Oriented
Truly
Not a prototyping language like javascript
Nor a procedural language with OOP bolted on
Classes
A class is a kind of master object
Can contain constants and methods
Instances of object can be created from a class, inheriting the traits of the class
Access Control
Methods in a class are public by default
Private methods are known only to the individual object
Protected methods can only be called by members of the class in which is was defined
Convention over Configuration
Notion that coding is reduced if we adopt a standard way of doing things
Eg., if we have a class "Pet" in our model that defines the characteristic of domestic animal, in rails, the database table created for us will be named "pets"
Other chunks of code look for each other by their common names
Action Pack
Since views and controllers interact so tightly, in rails they are combined in Action Pack
Action pack breaks a web request into view components and controller compoents
So an action usually involves a controller request to create, read, update, or delete (CRUD) some part of the model, followed by a view request to render a page
Creating a basic site
Three commandsrails democd demoruby script/generate controller Bark
This creates the framework
In summary
Ruby's syntax is pretty
Ruby is all about structure
Classes are easy to work with, if you're new, start with simple examples