Here is the Power Point Presentation on Ruby

cabbagepatchtapeInternet και Εφαρμογές Web

5 Φεβ 2013 (πριν από 4 χρόνια και 4 μήνες)

141 εμφανίσεις

Ruby on Rails

Presenter: Michael Mayer


Network Programming @ RPI

This presentation was adapted from a ThoughtWise presentation

By Obie Fernandez; originally presented on 10

Presentation Agenda

Very brief overview of Ruby

Description of Rails framework

Questions and Answers

Rails demo (if time allows…)

Why Ruby?

Write understandable code in few lines


Free (Very open license)


Truly object oriented

there are no primitives

Why not Ruby?

Lack of support for casting

Lack of documentation

Relatively small community

Some Coding Conventions

Method Chaining

print array.uniq.sort.reverse

(now that’s meta

Method Names include ! and ?


Iterators and Blocks vs. Loops

files.each { |file| process(file) }

Case usage:

Class names begin with a Capital letter

Constants are ALL_CAPS

Everything else

method call or a local variable

under_score instead of camelCase

Enough About Ruby!

Time to talk about Ruby on Rails!

Rails in a Nutshell

It is a rapid development framework; a framework is simply a set of
best practices and abstractions often accompanied by automation
scripts that, in combination, make SW development with specific
technologies easier.

Create database
driven web applications according to the Model
Control pattern of separation.

Favors Convention over Configuration!

Mostly written by David H. Hannson

A principal

Maintained by an active OS community!

Rails Architecture




Model classes are the "smart" domain objects
(e.g. Product) that hold business logic and know
how to persist themselves to a database

Views are HTML/XML templates

Controllers handle incoming requests (e.g.
Update Product) by manipulating the model and
directing data to the view

ActiveRecord API

Object/Relational Mapping Framework

Model classes use this API

Automatic mapping between columns and class attributes

Declarative configuration via macros

Dynamic finders

Associations, Aggregations, Tree and List Behaviors


Validation rules

Et cetera…

ActiveRecord Associations

like class methods for tying objects
together through foreign keys

Each adds a number of methods to the class

In combination with migrations, allows your
database to be DBMS agnostic

ActionController API

Controllers defined as classes that execute and then either
render a template or redirects

An action is a public method on the controller

Getting data in and out of controllers

Request parameters available in the @params hash
(and can be multidimensional)

Web session exposed as @session hash

Cookies exposed as @cookies hash

Redirect scope provided by @flash hash (unique to

From Controller to View

Rails gives you many rendering options…

Default template rendering

follow naming
conventions and magic happens

Explicitly render to particular action

Redirect to another action

Render a string response (or no response)

Approaches to View Templating


Embedded Ruby

Similar to JSP’s <% and <%= syntax or PHP’s <? syntax

Easy to learn and teach to designers

Execute in scope of controller

Denoted with .rhtml extension


Programmatic View Construction

Great for writing xml content

Denoted with .rxml extension

Embeddable in ERB templates

ERB Example

XmlMarkup Example

Layouts and Partials

Templates in app/views/layouts/ with the same
name as a controller will be automatically set as
that controller’s layout unless explicitly told

Partials are sub
templates that render a single

Partial template files follow convention

Easy API support for rendering collections of partials.

The Quest for
Pretty URLs

The responsibility of URL parsing is
handled by Rails itself. Why?

Not all webservers support rewriting

Allows Rails to function “out of the box” on almost
all webservers

Facilitates definition of custom URLs

Linked to URL helper methods such as url_for,
link_to, and redirect_to

Routing rules defined in config/routes.rb


ActionController::Routing::Routes.draw do |map|

# Priority based on creation: first created
> highest priority

# Keep in mind you can assign values other than :controller and :action

# You can have the root of your site routed by hooking up ''

# just remember to delete public/index.html.

map.connect '', :controller => "bakery"

map.connect 'query/:guid', :controller => “global", :action=>"query"

# Allow downloading Web Service WSDL as a file with an extension

map.connect ':controller/service.wsdl', :action => 'wsdl'

map.connect ':controller/:action/:id’
# Default


Rails to the Rescue

Actions that fail to perform as expected
throw exceptions

Exceptions can be rescued…

for public view (with a nice user
friendly explanation)

for developers view (with tons of debugging

By default, requests from localhost get developers view


Ruby’s Build System

Familiar to Ant users

Your build file is a written in Ruby

Basic build script provided with Rails project

The Rails Community

The developer community around Rails is
very helpful and excited

Rails Wiki

Rails Mailing List

very active


Get instant answers to most questions.
David and other Rails commiters are all
regularly present

What did I leave out?

ActionMailer API

ActionWebService API

ActiveSupport API


Scripts and Generators

Webrick web server

Et cetera…

Questions / Comments?

Thanks for listening!

Feel free to email me. I am one of your TAs after all… :]

Original presentation:


Time to see some code!