Anda di halaman 1dari 13

Ruby on Rails

What's Ruby
A programming language

What's Rails
Initially developed by David Heinemeier Hansson, out of his
work on Base camp, a project management system
It is a framework of scripts in ruby that provide for rapid
development of web applications, esp those with a database
back end
Rails can build the skeleton of an application, including the
database tables, in just a few commands

Ruby
Syntax
Ruby is largely and loosely based on perl (hence the name,
according to lore)
Completely object oriented

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

Playing on the Command Line


Ruby is an interpreter, just like php or bash:
Avatar:~ hays$ ruby
print "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

A simple class
class Cat
end
(but this class doesn't do or mean anything)

cat class

I want four attributes for a cat; name, color, type, and


attribute
class Cat # must be capitalized
attr_accessor :name, :type, :color, :attribute
def initialize(name, type, color, attribute)
@name = name
@type = type
@color = color
@attribute = attribute
end

Several concepts
creating a new cat
add a method
calling the method
Access Control
Variables
Arrays
Hashes
conditional

Rails

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
Contains the data of the application
Transient
Stored (eg Database)
Enforces "business" rules of the application
Attributes
Work flow

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

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

Several concepts
Processing URLs
The View
Creating a basic site
Directory Structure
Generating a database site

we provide online and classroom training


for Ruby on Rails

For More Details


www.asit.amcsquare.com
Wise Machines India Pvt Ltd
#360, Sri Sai Padma Arcade,
Varthur Main Road,
Ramagondanahalli,
Whitefiled ,Bangalore 560066.
We also having Branches in Hyderabad & Chennai

Anda mungkin juga menyukai