Ruby On Rails Presentation Barcamp Antwerp.Key
by Bert Goethals on Mar 22, 2009
- 1,754 views
Accessibility
Categories
Tags
More...Upload Details
Uploaded via SlideShare as Apple Keynote
Usage Rights
Statistics
- Favorites
- 2
- Downloads
- 17
- Comments
- 0
- Embed Views
- Views on SlideShare
- 1,750
- Total Views
- 1,754


daarvoor: PHP, Java, ASP.NET C#, COBOL, HTTP, CSS
leren developen op het web
Wat is RoR.. eerst en vooral het Ruby
Phython: easy, natural syntax
Perl’s Pragamatism: Gezond verstand en realisme aanleggen en praktish gericht zijn ipv theoretish
** Principal of Least Surprise
** Completely OO
** Syntax for programmers
introspection .methods method
redefine method in same class / redefine methods for an instance
Multiple inheritance like in c
A dynamic, object-oriented programming language with:
•a strong focus on simplicity and productivity
•an elegant, natural syntax
•roots in Lisp, Perl, and Smalltalk
leesbaar, te verwachten syntax
optional arguments (*args)
Reflection! (1.month is afhankelijk van Time.now)
nil is an Object
Class is an Object (word wat ingewikkeld)
Nu, wat is Rails dan?
- Abstraction (DB, environment)
- Geen SERVER
- Convention over Configuration
- MVC
Voor die gene die MVC niet kennen:
Model: Object represenatie van de data en business logic
View: Presentatie van de data
Conroller: Het gene er tussenin (haal data op om te displayen, regageert op user actions)
- Controllers
- Models
- Views
helpers voor views the helpen
ten eerste de Models
- Klass is a table
- Columns are attributes
- Rows are instances
Abstractie van alle database, en db type:
MySQL, PostgreSQL, SQLite, Oracle, MS SQLServer, and IBM DB2. out of the box
Het aanmaken van een tabel (een migration) is Database agnostisch.
ActiveRecord zal automatisch de tabel “posts” vinden (plural van Post) en al de attributen zullen aanwezig zijn als getters/setters
Free magic:
id column
created/updated_at
counters
Weinig code => veel functionaliteit
- associations (belongs_to, has_one, has_many, :through, conditions ... )
- Validations (uniqness, range, presence, :if, custom)
- named scope (pre defined pieces of queries, condition, order, grouping)
Deze method calls gebeuren dus vooral in de controllers
- reageert op de HTTP requests “actions”
OUt of the box krijgen we
- Securing een session (encoding the session info)
- Cross site scripting attacks afweren (session VS post variables)
- Vertalen van URL’s naar methods in controllers // Routing
- Als er een AR model niet gevonden word, 404 displayen, of een 500 page waneer er zich een andere excpetion voor doet
- Controller
- Action
- Params
Gedefinieerd in routes file,
Eigen routes of standaard routes / REST
CRUD over HTTP
PUT en DELETE zijn niet supported door Browsers (behalve in JS) en word gemuleerd door de Rails
HTTP is meer dan GET and POST (WebDAV, CalDAV) verbs
HTML, XML, JSON, ICAL, JS gebaseerd op de request
De view hoeft niet expliciet aangeroepen worden (default) view heeft zelfde naam als action
- Helper methods (link_to)
- translations t()
- url/path generators/helpers
action/name . format . processor
partials
layouts
Ze bevatten stukjes logica die meer dan een regel beslaan,
zodat de view zelf niet vervuilt word met teveel logica
- Login validatie,
- Rating van Items in de database (stars)
- Comments logic
- etc...
Dankzij convention over configuration:
- Bijna lege models (mapping en configuratie automatisch)
Configuration still possible
- legacy DB, highly custom systems
en included worden door objecten die het willen
Laat toe dat Models featured kunnen worden (dmv een feature model)
Alle logica is in de module
- association
- AR methods
- instance methods
- Klass methods
- validations ...
ActiveRecord zelf is ook aangepast, zodat elk model kan zeggen of het gefeatured kan worden
Waarom herhalen wat anderen al hebben geschreven?
taggable: full tagging system (zijn volledige tables, maar doen zich voor als array in model)
list: als order belangrijk is
paginate: limit queries, and pagination voor HTML (AR, AC)
default: complexe default values (uuid, time based, )
Ten slotte nog enkele plugins in detail
Authlogic voorziet een volledige authenticatie systeem
Definieer het User model and you are ready to roll
- Sessies gedragen zich net als andere modellen
- Password security is transparant
- tracken van login times
- create / confirmed / approved status van account
- etc...
- Zet zelf attributen in DB
- Manage files zelf, methods zoals public_path en local_path
- Thumbnails automatisch
- Processors toevoegen (OCR, red eyes...)
-
Dankuwel