Loading in 2 Seconds...
Loading in 2 Seconds...
Ruby on Rails Presentation to Agile Atlanta Group Originally presented May 10 ‘05. Obie Fernandez Agile Atlanta Founder / ThoughtWorks Technologist. Introduction. Why present Ruby on Rails to Agile Atlanta? Ruby is an agile language Ruby on Rails is Ruby’s Killer App
Agile Atlanta Founder /
Why present Ruby on Rails to Agile Atlanta?
Japanese Design Aesthetics Shine Through
Relevant because these principles were followed closely by the designer of Rails, David H. Hansson
Scandinavian Design Aesthetic
This principle is the supreme design goal of Ruby
Makes programmers happy and makes Ruby easy to learn
A.K.A. Principle of Least Effort
Especially on XML config files, getters, setters, etc…
Sounds reasonable enough, right?
All classes derived from Object including Class (like Java) but there are no primitives (not like Java at all)
What about Ruby on Rails?
Includes everything needed to create database-driven web applications according to the Model-View-Control pattern of separation.
Mostly written by David H. Hannson
Over 100 additional contributors to the Rails codebase in 9 months!
Todo List Tutorial Project
by Vincent Foley http://manuals.rubyonrails.com/read/book/7
Based on Martin Fowler’s ActiveRecord pattern
From Patterns of Enterprise Architecture
An object that wraps a row in a database table or view, encapsulates the database access, and adds domain logic on that data.
Convention over Configuration (Applies to all of Rails)
Admit the Database
Object/Relational Mapping Framework
Aggregation expresses a composed of relationship
The ActiveRecord::Acts module has super cool features that enhance your models behavior
Provides the capabilities for sorting and reordering a number of objects in list
Model a tree structure by providing a parent association and a children association
Similiar to Tree, but with the added feature that you can select the children and all of it’s descendants with a single query!
Macro-like class methods for tying objects together through foreign keys
ActiveRecord objects will automatically record creation and/or update timestamps of database objects if columns with the names created_at / created_on or updated_at / updated_on are present in your db table
Simple declarative transaction support on both object and database level
# Just database transaction
# Object transaction
Account.transaction(david, mary) do
ActiveRecord lets you do
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
The simple way to add Pre and Post processing to actions
Rails gives you many rendering options…
ERB – Embedded Ruby
XmlMarkup – Programmatic View Construction
Aren’t Rails programmers going to be tempted to put a bunch of application logic in the templates?
The short answer is no.
JSPs are a less painful way to add logic to a screen. Due to the lower pain associated with their use, it is very tempting to add inappropriate code to them
That’s simply not the case with Rails!
Ruby is an excellent language for view logic (succinct, readable) and Rails is also made out of all Ruby. So there\'s no longing for a better suited template language and there\'s no pain relief in misappropriating business logic into the view.
- David H. Hansson
Templates in app/views/layouts/ with the same name as a controller will be automatically set as that controller’s layout unless explicitly told otherwise
Partials are sub-templates that render a single object
Enhance performance by keeping the result of calculations, renderings, and database calls around for subsequent requests
Action Controller offers 3 levels of granularity
Sweepers are responsible for expiring caches when model objects change
Macro-style automatic fetching of your model for multiple views, or explicit fetching for single actions
Help you spend time writing meaningful code…
Reports the approximate distance in time between to Time objects. For example, if the distance is 47 minutes, it\'ll return "about 1 hour“
AJAX in one line! Creates link to a remote action that’s called in the background using XMLHttpRequest. The result of that request can then be inserted into the browser’s DOM
More AJAX! Links page to a remote action that’s called in the background using XMLHttpRequest. The result of that request can be inserted into the browser’s DOM
NumberHelper::human_size, number_to_currency, number_to_phone, etc…
You get the picture!
The responsibility of URL parsing is handled by Rails itself. Why?
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
Actions that fail to perform as expected throw exceptions
Exceptions can either be rescued…
By default, requests from localhost get developers view
Rails utility methods
Rails’ built-in email service
It’s easy to do web services in Rails
Use YAML sample data for testing
Basecamp (info as of late April ’05)
The developer community around Rails is very helpful and excited