SlideShare a Scribd company logo
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 Ruby on Rails promotes agile practices
Presentation Agenda Brief overview of Ruby Rails Demonstration Description of Rails framework Questions and Answers
Why Ruby? Write more understandable code in less lines Free (Very open license) Extensible
Principles of Ruby Japanese Design Aesthetics Shine Through Focus on human factors Principle of Least Surprise Principle of Succinctness Relevant because these principles were followed closely by the designer of Rails, David H. Hansson  Scandinavian Design Aesthetic
The Principle of Least Surprise This principle is the supreme design goal of Ruby Makes programmers happy and makes Ruby easy to learn Examples What class is an object? o.class Is it Array#size or Array#length? same method – they’re aliased What are the differences between arrays? diff = ary1 – ary2 union = ary1 + ary2
Principle of Succinctness A.K.A.  Principle of Least Effort We don’t like to waste time Especially on XML config files, getters, setters, etc…  The quicker we program, the more we accomplish Sounds reasonable enough, right? Less code means less bugs
Ruby is Truly Object-Oriented All classes derived from  Object i ncluding  Class  (like Java) but there are no primitives (not like Java at all) Ruby uses single-inheritance Mixins give you the power of multiple inheritance without the headaches Modules allow addition of behaviors to a class Reflection is built in along with lots of other highly dynamic metadata features Things like ‘=‘ and ‘+’ that you might think are operators are actually methods (like Smalltalk)
Some Coding Conventions Method Chaining print array.uniq.sort.reverse Method Names include ! and ? ary.sort!  (discuss bang if there is time) 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
Dynamic Programming Duck Typing Based on signatures, not class inheritance Dynamic Dispatch A key concept of OOP: methods are actually messages that are  sent  to an object instance Dynamic Behavior Reflection Scope Reopening (Kind of like AOP) Eval Breakpoint debugger
Enough About Ruby! What about Ruby on Rails?
Rails in a Nutshell  Includes everything needed to create database-driven web applications according to the Model-View-Control pattern of separation. Mostly written by David H. Hannson Talented designer Dream is to change the world A 37signals.com principal – World class designers Over 100 additional contributors to the Rails codebase in 9 months!
The Obligatory Architecture Slide
Demo Todo List Tutorial Project by Vincent Foley http://manuals.rubyonrails.com/read/book/7
Model – View – Controller  Model classes are the "smart" domain objects (such as Account, Product, Person, Post) that hold business logic and know how to persist themselves to a database Views are HTML templates Controllers handle incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view
Model Classes 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.
ActiveRecord Convention over Configuration (Applies to all of Rails) No XML files!  Lots of reflection and run-time extension  Magic is not inherently a bad word  Admit the Database Lets you drop down to SQL for odd cases and performance  Doesn‘t attempt to duplicate or replace data definitions
ActiveRecord API Object/Relational Mapping Framework Automatic mapping between columns and class attributes Declarative configuration via macros Dynamic finders Associations, Aggregations, Tree and List Behaviors Locking Lifecycle Callbacks Single-table inheritance supported Eager fetching supported Validation rules More…
ActiveRecord Aggregations Aggregation expresses a  composed of  relationship Define  value  objects by using composed_of method Tells Rails how value objects are created from the attributes of the entity object when the entity is initialized and… how it can be turned back into attributes when the entity is saved to the database Adds a reader and writer method for manipulating a value object Value objects should be immutable and that requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to change value objects result in a TypeError
ActiveRecord Models  are Multi-talented  actors The ActiveRecord::Acts module has super cool features that enhance your models behavior acts_as_list Provides the capabilities for sorting and reordering a number of objects in list acts_as_tree Model a tree structure by providing a parent association and a children association acts_as_nested_set Similiar to Tree, but with the added feature that you can select the children and all of it’s descendants with a single query!
ActiveRecord Associations Macro-like class methods for tying objects together through foreign keys Each adds a number of methods to the class  Works much the same way as Ruby’s own attr* methods
ActiveRecord Timestamps Magic  timestamps! 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
ActiveRecord Transactions Simple declarative transaction support on both object and database level # Just database transaction  Account.transaction do david.withdrawal(100) mary.deposit(100)  end  # Object transaction Account.transaction(david, mary) do  david.withdrawal(100) mary.deposit(100)  end
ActiveRecord vs Hibernate Instead of ActiveRecord lets you do
Rails Logging
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 Rails)
Filters and Request Interception The simple way to add Pre and Post processing to actions  Access to the request, response, and instance variables set by other filters or the action Controller inheritance hierarchies share filters downwards, but subclasses can also add new filters Target specific actions with :only and :except options Flexible Filter definition method reference (by symbol) external class inline method (proc)
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)
View Template Approaches ERB – Embedded Ruby Similar to JSPs <% and <%= syntax Easy to learn and teach to designers Execute in scope of controller Denoted with .rhtml extension XmlMarkup – Programmatic View Construction Great for writing xhtml and xml content Denoted with .rxml extension Embeddable in ERB templates
ERB Example
XmlMarkup Example
Similar to JSP is a Good Thing? 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
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 otherwise Partials are sub-templates that render a single object Partial template files follow convention Easy API support for rendering collections of partials.
Built-in Caching Enhance performance by keeping the result of calculations, renderings, and database calls around for subsequent requests Action Controller offers 3 levels of granularity Page Action Fragment Sweepers are responsible for expiring caches when model objects change
Page Caching Entire action output of is stored as a HTML file that the web server can serve  As much as 100 times faster than going the process of dynamically generating the content Only available to stateless pages where all visitors are treated the same Easy to implement…
Action Caching Entire output of the response is cached Every request still goes to the controller filters are run before the cache is served allows for authentication and other restrictions on whether someone are supposed to see the cache
Fragment Caching Caches parts of templates without caching the entire action Use when elements of an action change frequently and other parts rarely change or are okay to share among requests Four options for storage FileStore – Fragments shared on file system by all processes MemoryStore – Caches fragments in memory per process DrbStore – Fragments cached on a separate, shared process MemCachedStore – Uses Danga’s MemCached open source caching server
Pagination Macro-style automatic fetching of your model for multiple views, or explicit fetching for single actions Included for all controllers Configure as much or as little as desired PaginationHelper module has methods for generating pagination links in your template
Helper Modules Help you spend time writing meaningful code… ActiveRecordHelper AssetTagHelper DateHelper DebugHelper FormHelper(s) JavascriptHelper NumberHelper PaginationHelper TagHelper TextHelper UrlHelper
Helper Methods Examples DateHelper::distance_of_time_in_words Reports the approximate distance in time between to Time objects. For example, if the distance is 47 minutes, it'll return &quot;about 1 hour“ JavascriptHelper::link_to_remote 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  JavascriptHelper::periodically_call_remote 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 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
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 => &quot;bakery&quot; map.connect 'query/:guid', :controller => “global&quot;, :action=>&quot;query&quot; # Allow downloading Web Service WSDL as a file with an extension map.connect ':controller/service.wsdl', :action => 'wsdl' map.connect ':controller/:action/:id’  # Default end
Rails to the Rescue Actions that fail to perform as expected throw exceptions Exceptions can either be rescued… for public view (with a nice user-friendly explanation) for developers view (with tons of debugging information) By default, requests from localhost get developers view
ActiveSupport API Rails utility methods Date conversion Number handling String conversions and inflection Time calculations
ActionMailer API Rails’ built-in email service Write email controllers in same way as web controllers Integrated with templating system
ActionWebService API It’s easy to do web services in Rails Rails has built-in support for SOAP and XML-RPC Struct  base class can be used to represent structured types that don’t have ActiveRecord implementations or to avoid exposing an entire model to callers Examples Define a web services client in one line Add a web service to a controller (next slide)
Defining a WebService
Fixtures Use YAML sample data for testing Each YAML fixture (ie. record) is given a name and is followed by an indented list of key/value pairs in the &quot;key: value&quot; format.  Records are separated by a blank line
Unit Testing Rails includes Ruby’s test/unit Rake pre-configured to run test suite or individual tests Easy to load fixtures into a test case
Rake Ruby’s Build System Familiar to Ant users Your build file is a written in Ruby Basic build script provided with Rails project
Rails Success Story Basecamp (info as of late April ’05) Average lines of code for an action in Basecamp is  5 Written in 9 months Tens of thousands of users 300k dynamic page renders/day Hosted on two app servers with 15 fastcgi processes each + one MySQL server
The Rails Community The developer community around Rails is very helpful and excited Rails Wiki - http://wiki.rubyonrails.com/ Rails Mailing List – very active IRC – Get instant answers to most questions. David and other Rails commiters are all regularly present
Ad

More Related Content

What's hot (20)

Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
DelphiCon
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
[2015/2016] Backbone JS
[2015/2016] Backbone JS[2015/2016] Backbone JS
[2015/2016] Backbone JS
Ivano Malavolta
 
[2015/2016] JavaScript
[2015/2016] JavaScript[2015/2016] JavaScript
[2015/2016] JavaScript
Ivano Malavolta
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Agnieszka Figiel
 
What Is Hobo ?
What Is Hobo ?What Is Hobo ?
What Is Hobo ?
Evarist Lobo
 
25 Real Life Tips In Ruby on Rails Development
25 Real Life Tips In Ruby on Rails Development25 Real Life Tips In Ruby on Rails Development
25 Real Life Tips In Ruby on Rails Development
Belighted
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
reybango
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
Wen-Tien Chang
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
Ivano Malavolta
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
Rami Sayar
 
ADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guideADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guide
Luc Bors
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
Icalia Labs
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion
 
Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
Gabriel Walt
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
Justin Edelson
 
Jsp
JspJsp
Jsp
Pooja Verma
 
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory CourseRuby on Rails 101 - Presentation Slides for a Five Day Introductory Course
Ruby on Rails 101 - Presentation Slides for a Five Day Introductory Course
peter_marklund
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
DelphiCon
 
2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop2011-02-03 LA RubyConf Rails3 TDD Workshop
2011-02-03 LA RubyConf Rails3 TDD Workshop
Wolfram Arnold
 
Building Web Interface On Rails
Building Web Interface On RailsBuilding Web Interface On Rails
Building Web Interface On Rails
Wen-Tien Chang
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
Agnieszka Figiel
 
25 Real Life Tips In Ruby on Rails Development
25 Real Life Tips In Ruby on Rails Development25 Real Life Tips In Ruby on Rails Development
25 Real Life Tips In Ruby on Rails Development
Belighted
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
reybango
 
FITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive ImagesFITC - Exploring Art-Directed Responsive Images
FITC - Exploring Art-Directed Responsive Images
Rami Sayar
 
ADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guideADF Mobile: 10 Things you don't get from the developers guide
ADF Mobile: 10 Things you don't get from the developers guide
Luc Bors
 
Rails Best Practices
Rails Best PracticesRails Best Practices
Rails Best Practices
Icalia Labs
 
MVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on RailsMVC Demystified: Essence of Ruby on Rails
MVC Demystified: Essence of Ruby on Rails
codeinmotion
 
Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010Ruby On Rails Seminar Basis Softexpo Feb2010
Ruby On Rails Seminar Basis Softexpo Feb2010
arif44
 
AEM Sightly Template Language
AEM Sightly Template LanguageAEM Sightly Template Language
AEM Sightly Template Language
Gabriel Walt
 
Mastering the Sling Rewriter
Mastering the Sling RewriterMastering the Sling Rewriter
Mastering the Sling Rewriter
Justin Edelson
 

Similar to Ruby On Rails (20)

Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
chamomilla
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoR
Sumanth krishna
 
Ruby on rails for beginers
Ruby on rails for beginersRuby on rails for beginers
Ruby on rails for beginers
shanmukhareddy dasi
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
TAInteractive
 
Ruby on Rails
Ruby on Rails Ruby on Rails
Ruby on Rails
thinkahead.net
 
Ruby on rails
Ruby on railsRuby on rails
Ruby on rails
TAInteractive
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
Siddhesh Bhobe
 
Rails interview questions
Rails interview questionsRails interview questions
Rails interview questions
Durgesh Tripathi
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User Group
Jose de Leon
 
Ruby on rails RAD
Ruby on rails RADRuby on rails RAD
Ruby on rails RAD
Alina Danila
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in Smalltalk
ESUG
 
Ruby on Rails
Ruby on RailsRuby on Rails
Ruby on Rails
Sadakathullah Appa College
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
Gary Pedretti
 
Intro ror
Intro rorIntro ror
Intro ror
tim_tang
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
Gautam Rege
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
webuploader
 
Hibernate
HibernateHibernate
Hibernate
Murali Pachiyappan
 
Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL Databases
Jon Meredith
 
Introducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoRIntroducing Ruby/MVC/RoR
Introducing Ruby/MVC/RoR
Sumanth krishna
 
Ruby On Rails Siddhesh
Ruby On Rails SiddheshRuby On Rails Siddhesh
Ruby On Rails Siddhesh
Siddhesh Bhobe
 
Ruby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User GroupRuby On Rails - Rochester K Linux User Group
Ruby On Rails - Rochester K Linux User Group
Jose de Leon
 
Object- Relational Persistence in Smalltalk
Object- Relational Persistence in SmalltalkObject- Relational Persistence in Smalltalk
Object- Relational Persistence in Smalltalk
ESUG
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
Gary Pedretti
 
Workin ontherailsroad
Workin ontherailsroadWorkin ontherailsroad
Workin ontherailsroad
Jim Jones
 
WorkinOnTheRailsRoad
WorkinOnTheRailsRoadWorkinOnTheRailsRoad
WorkinOnTheRailsRoad
webuploader
 
Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!Ruby on Rails: Building Web Applications Is Fun Again!
Ruby on Rails: Building Web Applications Is Fun Again!
judofyr
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL Databases
Jon Meredith
 
Ad

Recently uploaded (20)

TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
Kirill Klip
 
AlaskaSilver Corporate Presentation Apr 28 2025.pdf
AlaskaSilver Corporate Presentation Apr 28 2025.pdfAlaskaSilver Corporate Presentation Apr 28 2025.pdf
AlaskaSilver Corporate Presentation Apr 28 2025.pdf
Western Alaska Minerals Corp.
 
Harnessing Hyper-Localisation: A New Era in Retail Strategy
Harnessing Hyper-Localisation: A New Era in Retail StrategyHarnessing Hyper-Localisation: A New Era in Retail Strategy
Harnessing Hyper-Localisation: A New Era in Retail Strategy
RUPAL AGARWAL
 
Entrepreneurship: Practicum on Business Plan.ppt
Entrepreneurship: Practicum on Business Plan.pptEntrepreneurship: Practicum on Business Plan.ppt
Entrepreneurship: Practicum on Business Plan.ppt
Tribhuvan University
 
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand AwarenessAlec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler
 
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
AMITKUMARVERMA479091
 
NewBase 28 April 2025 Energy News issue - 1783 by Khaled Al Awadi_compressed...
NewBase 28 April 2025  Energy News issue - 1783 by Khaled Al Awadi_compressed...NewBase 28 April 2025  Energy News issue - 1783 by Khaled Al Awadi_compressed...
NewBase 28 April 2025 Energy News issue - 1783 by Khaled Al Awadi_compressed...
Khaled Al Awadi
 
Disinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key FindingsDisinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key Findings
MariumAbdulhussein
 
BeMetals_Presentation_May_2025 .pdf
BeMetals_Presentation_May_2025      .pdfBeMetals_Presentation_May_2025      .pdf
BeMetals_Presentation_May_2025 .pdf
DerekIwanaka2
 
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
TheoRuby
 
Solaris Resources Presentation - Corporate April 2025.pdf
Solaris Resources Presentation - Corporate April 2025.pdfSolaris Resources Presentation - Corporate April 2025.pdf
Solaris Resources Presentation - Corporate April 2025.pdf
pchambers2
 
Influence of Career Development on Retention of Employees in Private Univers...
Influence of Career Development on Retention of  Employees in Private Univers...Influence of Career Development on Retention of  Employees in Private Univers...
Influence of Career Development on Retention of Employees in Private Univers...
publication11
 
20250428 CDB Investor Deck_Apr25_vFF.pdf
20250428 CDB Investor Deck_Apr25_vFF.pdf20250428 CDB Investor Deck_Apr25_vFF.pdf
20250428 CDB Investor Deck_Apr25_vFF.pdf
yihong30
 
Region Research (Hiring Trends) Vietnam 2025.pdf
Region Research (Hiring Trends) Vietnam 2025.pdfRegion Research (Hiring Trends) Vietnam 2025.pdf
Region Research (Hiring Trends) Vietnam 2025.pdf
Consultonmic
 
From Sunlight to Savings The Rise of Homegrown Solar Power.pdf
From Sunlight to Savings The Rise of Homegrown Solar Power.pdfFrom Sunlight to Savings The Rise of Homegrown Solar Power.pdf
From Sunlight to Savings The Rise of Homegrown Solar Power.pdf
Insolation Energy
 
Treis & Friends One sheet - Portfolio IV
Treis & Friends One sheet - Portfolio IVTreis & Friends One sheet - Portfolio IV
Treis & Friends One sheet - Portfolio IV
aparicioregina7
 
TNR Gold Shotgun Gold Project Presentation
TNR Gold Shotgun Gold Project PresentationTNR Gold Shotgun Gold Project Presentation
TNR Gold Shotgun Gold Project Presentation
Kirill Klip
 
Progress Report - Workday Analyst Summit 2025 - Change fo the better coming
Progress Report - Workday Analyst Summit 2025 - Change fo the better comingProgress Report - Workday Analyst Summit 2025 - Change fo the better coming
Progress Report - Workday Analyst Summit 2025 - Change fo the better coming
Holger Mueller
 
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining PresentationTNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
Kirill Klip
 
SAP S/4HANA Asset Management - Functions and Innovations
SAP S/4HANA Asset Management - Functions and InnovationsSAP S/4HANA Asset Management - Functions and Innovations
SAP S/4HANA Asset Management - Functions and Innovations
Course17
 
TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
TNR Gold Investor Presentation - Building The Green Energy Metals Royalty and...
Kirill Klip
 
Harnessing Hyper-Localisation: A New Era in Retail Strategy
Harnessing Hyper-Localisation: A New Era in Retail StrategyHarnessing Hyper-Localisation: A New Era in Retail Strategy
Harnessing Hyper-Localisation: A New Era in Retail Strategy
RUPAL AGARWAL
 
Entrepreneurship: Practicum on Business Plan.ppt
Entrepreneurship: Practicum on Business Plan.pptEntrepreneurship: Practicum on Business Plan.ppt
Entrepreneurship: Practicum on Business Plan.ppt
Tribhuvan University
 
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand AwarenessAlec Lawler - A Passion For Building Brand Awareness
Alec Lawler - A Passion For Building Brand Awareness
Alec Lawler
 
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
PREDICTION%20AND%20ANALYSIS%20OF%20ADMET%20PROPERTIES%20OF%20NEW%20MOLECULE%2...
AMITKUMARVERMA479091
 
NewBase 28 April 2025 Energy News issue - 1783 by Khaled Al Awadi_compressed...
NewBase 28 April 2025  Energy News issue - 1783 by Khaled Al Awadi_compressed...NewBase 28 April 2025  Energy News issue - 1783 by Khaled Al Awadi_compressed...
NewBase 28 April 2025 Energy News issue - 1783 by Khaled Al Awadi_compressed...
Khaled Al Awadi
 
Disinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key FindingsDisinformation in Society Report 2025 Key Findings
Disinformation in Society Report 2025 Key Findings
MariumAbdulhussein
 
BeMetals_Presentation_May_2025 .pdf
BeMetals_Presentation_May_2025      .pdfBeMetals_Presentation_May_2025      .pdf
BeMetals_Presentation_May_2025 .pdf
DerekIwanaka2
 
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
Web Design Creating User-Friendly and Visually Engaging Websites - April 2025...
TheoRuby
 
Solaris Resources Presentation - Corporate April 2025.pdf
Solaris Resources Presentation - Corporate April 2025.pdfSolaris Resources Presentation - Corporate April 2025.pdf
Solaris Resources Presentation - Corporate April 2025.pdf
pchambers2
 
Influence of Career Development on Retention of Employees in Private Univers...
Influence of Career Development on Retention of  Employees in Private Univers...Influence of Career Development on Retention of  Employees in Private Univers...
Influence of Career Development on Retention of Employees in Private Univers...
publication11
 
20250428 CDB Investor Deck_Apr25_vFF.pdf
20250428 CDB Investor Deck_Apr25_vFF.pdf20250428 CDB Investor Deck_Apr25_vFF.pdf
20250428 CDB Investor Deck_Apr25_vFF.pdf
yihong30
 
Region Research (Hiring Trends) Vietnam 2025.pdf
Region Research (Hiring Trends) Vietnam 2025.pdfRegion Research (Hiring Trends) Vietnam 2025.pdf
Region Research (Hiring Trends) Vietnam 2025.pdf
Consultonmic
 
From Sunlight to Savings The Rise of Homegrown Solar Power.pdf
From Sunlight to Savings The Rise of Homegrown Solar Power.pdfFrom Sunlight to Savings The Rise of Homegrown Solar Power.pdf
From Sunlight to Savings The Rise of Homegrown Solar Power.pdf
Insolation Energy
 
Treis & Friends One sheet - Portfolio IV
Treis & Friends One sheet - Portfolio IVTreis & Friends One sheet - Portfolio IV
Treis & Friends One sheet - Portfolio IV
aparicioregina7
 
TNR Gold Shotgun Gold Project Presentation
TNR Gold Shotgun Gold Project PresentationTNR Gold Shotgun Gold Project Presentation
TNR Gold Shotgun Gold Project Presentation
Kirill Klip
 
Progress Report - Workday Analyst Summit 2025 - Change fo the better coming
Progress Report - Workday Analyst Summit 2025 - Change fo the better comingProgress Report - Workday Analyst Summit 2025 - Change fo the better coming
Progress Report - Workday Analyst Summit 2025 - Change fo the better coming
Holger Mueller
 
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining PresentationTNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
TNR Gold Los Azules Copper NSR Royalty Holding with McEwen Mining Presentation
Kirill Klip
 
SAP S/4HANA Asset Management - Functions and Innovations
SAP S/4HANA Asset Management - Functions and InnovationsSAP S/4HANA Asset Management - Functions and Innovations
SAP S/4HANA Asset Management - Functions and Innovations
Course17
 
Ad

Ruby On Rails

  • 1. Ruby on Rails Presentation to Agile Atlanta Group Originally presented May 10 ‘05 Obie Fernandez Agile Atlanta Founder / ThoughtWorks Technologist
  • 2. Introduction Why present Ruby on Rails to Agile Atlanta? Ruby is an agile language Ruby on Rails is Ruby’s Killer App Ruby on Rails promotes agile practices
  • 3. Presentation Agenda Brief overview of Ruby Rails Demonstration Description of Rails framework Questions and Answers
  • 4. Why Ruby? Write more understandable code in less lines Free (Very open license) Extensible
  • 5. Principles of Ruby Japanese Design Aesthetics Shine Through Focus on human factors Principle of Least Surprise Principle of Succinctness Relevant because these principles were followed closely by the designer of Rails, David H. Hansson Scandinavian Design Aesthetic
  • 6. The Principle of Least Surprise This principle is the supreme design goal of Ruby Makes programmers happy and makes Ruby easy to learn Examples What class is an object? o.class Is it Array#size or Array#length? same method – they’re aliased What are the differences between arrays? diff = ary1 – ary2 union = ary1 + ary2
  • 7. Principle of Succinctness A.K.A. Principle of Least Effort We don’t like to waste time Especially on XML config files, getters, setters, etc… The quicker we program, the more we accomplish Sounds reasonable enough, right? Less code means less bugs
  • 8. Ruby is Truly Object-Oriented All classes derived from Object i ncluding Class (like Java) but there are no primitives (not like Java at all) Ruby uses single-inheritance Mixins give you the power of multiple inheritance without the headaches Modules allow addition of behaviors to a class Reflection is built in along with lots of other highly dynamic metadata features Things like ‘=‘ and ‘+’ that you might think are operators are actually methods (like Smalltalk)
  • 9. Some Coding Conventions Method Chaining print array.uniq.sort.reverse Method Names include ! and ? ary.sort! (discuss bang if there is time) 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
  • 10. Dynamic Programming Duck Typing Based on signatures, not class inheritance Dynamic Dispatch A key concept of OOP: methods are actually messages that are sent to an object instance Dynamic Behavior Reflection Scope Reopening (Kind of like AOP) Eval Breakpoint debugger
  • 11. Enough About Ruby! What about Ruby on Rails?
  • 12. Rails in a Nutshell Includes everything needed to create database-driven web applications according to the Model-View-Control pattern of separation. Mostly written by David H. Hannson Talented designer Dream is to change the world A 37signals.com principal – World class designers Over 100 additional contributors to the Rails codebase in 9 months!
  • 14. Demo Todo List Tutorial Project by Vincent Foley http://manuals.rubyonrails.com/read/book/7
  • 15. Model – View – Controller Model classes are the &quot;smart&quot; domain objects (such as Account, Product, Person, Post) that hold business logic and know how to persist themselves to a database Views are HTML templates Controllers handle incoming requests (such as Save New Account, Update Product, Show Post) by manipulating the model and directing data to the view
  • 16. Model Classes 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.
  • 17. ActiveRecord Convention over Configuration (Applies to all of Rails) No XML files! Lots of reflection and run-time extension Magic is not inherently a bad word Admit the Database Lets you drop down to SQL for odd cases and performance Doesn‘t attempt to duplicate or replace data definitions
  • 18. ActiveRecord API Object/Relational Mapping Framework Automatic mapping between columns and class attributes Declarative configuration via macros Dynamic finders Associations, Aggregations, Tree and List Behaviors Locking Lifecycle Callbacks Single-table inheritance supported Eager fetching supported Validation rules More…
  • 19. ActiveRecord Aggregations Aggregation expresses a composed of relationship Define value objects by using composed_of method Tells Rails how value objects are created from the attributes of the entity object when the entity is initialized and… how it can be turned back into attributes when the entity is saved to the database Adds a reader and writer method for manipulating a value object Value objects should be immutable and that requirement is enforced by Active Record by freezing any object assigned as a value object. Attempting to change value objects result in a TypeError
  • 20. ActiveRecord Models are Multi-talented actors The ActiveRecord::Acts module has super cool features that enhance your models behavior acts_as_list Provides the capabilities for sorting and reordering a number of objects in list acts_as_tree Model a tree structure by providing a parent association and a children association acts_as_nested_set Similiar to Tree, but with the added feature that you can select the children and all of it’s descendants with a single query!
  • 21. ActiveRecord Associations Macro-like class methods for tying objects together through foreign keys Each adds a number of methods to the class Works much the same way as Ruby’s own attr* methods
  • 22. ActiveRecord Timestamps Magic timestamps! 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
  • 23. ActiveRecord Transactions Simple declarative transaction support on both object and database level # Just database transaction Account.transaction do david.withdrawal(100) mary.deposit(100) end # Object transaction Account.transaction(david, mary) do david.withdrawal(100) mary.deposit(100) end
  • 24. ActiveRecord vs Hibernate Instead of ActiveRecord lets you do
  • 26. 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 Rails)
  • 27. Filters and Request Interception The simple way to add Pre and Post processing to actions Access to the request, response, and instance variables set by other filters or the action Controller inheritance hierarchies share filters downwards, but subclasses can also add new filters Target specific actions with :only and :except options Flexible Filter definition method reference (by symbol) external class inline method (proc)
  • 28. 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)
  • 29. View Template Approaches ERB – Embedded Ruby Similar to JSPs <% and <%= syntax Easy to learn and teach to designers Execute in scope of controller Denoted with .rhtml extension XmlMarkup – Programmatic View Construction Great for writing xhtml and xml content Denoted with .rxml extension Embeddable in ERB templates
  • 32. Similar to JSP is a Good Thing? 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
  • 33. 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 otherwise Partials are sub-templates that render a single object Partial template files follow convention Easy API support for rendering collections of partials.
  • 34. Built-in Caching Enhance performance by keeping the result of calculations, renderings, and database calls around for subsequent requests Action Controller offers 3 levels of granularity Page Action Fragment Sweepers are responsible for expiring caches when model objects change
  • 35. Page Caching Entire action output of is stored as a HTML file that the web server can serve As much as 100 times faster than going the process of dynamically generating the content Only available to stateless pages where all visitors are treated the same Easy to implement…
  • 36. Action Caching Entire output of the response is cached Every request still goes to the controller filters are run before the cache is served allows for authentication and other restrictions on whether someone are supposed to see the cache
  • 37. Fragment Caching Caches parts of templates without caching the entire action Use when elements of an action change frequently and other parts rarely change or are okay to share among requests Four options for storage FileStore – Fragments shared on file system by all processes MemoryStore – Caches fragments in memory per process DrbStore – Fragments cached on a separate, shared process MemCachedStore – Uses Danga’s MemCached open source caching server
  • 38. Pagination Macro-style automatic fetching of your model for multiple views, or explicit fetching for single actions Included for all controllers Configure as much or as little as desired PaginationHelper module has methods for generating pagination links in your template
  • 39. Helper Modules Help you spend time writing meaningful code… ActiveRecordHelper AssetTagHelper DateHelper DebugHelper FormHelper(s) JavascriptHelper NumberHelper PaginationHelper TagHelper TextHelper UrlHelper
  • 40. Helper Methods Examples DateHelper::distance_of_time_in_words Reports the approximate distance in time between to Time objects. For example, if the distance is 47 minutes, it'll return &quot;about 1 hour“ JavascriptHelper::link_to_remote 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 JavascriptHelper::periodically_call_remote 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!
  • 41. 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
  • 42. 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 => &quot;bakery&quot; map.connect 'query/:guid', :controller => “global&quot;, :action=>&quot;query&quot; # Allow downloading Web Service WSDL as a file with an extension map.connect ':controller/service.wsdl', :action => 'wsdl' map.connect ':controller/:action/:id’ # Default end
  • 43. Rails to the Rescue Actions that fail to perform as expected throw exceptions Exceptions can either be rescued… for public view (with a nice user-friendly explanation) for developers view (with tons of debugging information) By default, requests from localhost get developers view
  • 44. ActiveSupport API Rails utility methods Date conversion Number handling String conversions and inflection Time calculations
  • 45. ActionMailer API Rails’ built-in email service Write email controllers in same way as web controllers Integrated with templating system
  • 46. ActionWebService API It’s easy to do web services in Rails Rails has built-in support for SOAP and XML-RPC Struct base class can be used to represent structured types that don’t have ActiveRecord implementations or to avoid exposing an entire model to callers Examples Define a web services client in one line Add a web service to a controller (next slide)
  • 48. Fixtures Use YAML sample data for testing Each YAML fixture (ie. record) is given a name and is followed by an indented list of key/value pairs in the &quot;key: value&quot; format. Records are separated by a blank line
  • 49. Unit Testing Rails includes Ruby’s test/unit Rake pre-configured to run test suite or individual tests Easy to load fixtures into a test case
  • 50. Rake Ruby’s Build System Familiar to Ant users Your build file is a written in Ruby Basic build script provided with Rails project
  • 51. Rails Success Story Basecamp (info as of late April ’05) Average lines of code for an action in Basecamp is 5 Written in 9 months Tens of thousands of users 300k dynamic page renders/day Hosted on two app servers with 15 fastcgi processes each + one MySQL server
  • 52. The Rails Community The developer community around Rails is very helpful and excited Rails Wiki - http://wiki.rubyonrails.com/ Rails Mailing List – very active IRC – Get instant answers to most questions. David and other Rails commiters are all regularly present

Editor's Notes

  • #2: &lt;rdf:RDF xmlns=&amp;quot;http://web.resource.org/cc/&amp;quot; xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:rdf=&amp;quot;http://www.w3.org/1999/02/22-rdf-syntax-ns#&amp;quot;&gt; &lt;Work rdf:about=&amp;quot;&amp;quot;&gt; &lt;dc:title&gt;Ruby on Rails&lt;/dc:title&gt; &lt;dc:date&gt;2005&lt;/dc:date&gt; &lt;dc:description&gt;Powerpoint Presentation: Introduction to Ruby and Ruby on Rails given to the Agile Atlanta user group on 5/10/2005 &lt;/dc:description&gt; &lt;dc:creator&gt;&lt;Agent&gt; &lt;dc:title&gt;Obed Fernandez&lt;/dc:title&gt; &lt;/Agent&gt;&lt;/dc:creator&gt; &lt;dc:rights&gt;&lt;Agent&gt; &lt;dc:title&gt;Obed Fernandez&lt;/dc:title&gt; &lt;/Agent&gt;&lt;/dc:rights&gt; &lt;license rdf:resource=&amp;quot;http://creativecommons.org/licenses/by-sa/2.0/&amp;quot; /&gt; &lt;/Work&gt; &lt;License rdf:about=&amp;quot;http://creativecommons.org/licenses/by-sa/2.0/&amp;quot;&gt; &lt;permits rdf:resource=&amp;quot;http://web.resource.org/cc/Reproduction&amp;quot; /&gt; &lt;permits rdf:resource=&amp;quot;http://web.resource.org/cc/Distribution&amp;quot; /&gt; &lt;requires rdf:resource=&amp;quot;http://web.resource.org/cc/Notice&amp;quot; /&gt; &lt;requires rdf:resource=&amp;quot;http://web.resource.org/cc/Attribution&amp;quot; /&gt; &lt;permits rdf:resource=&amp;quot;http://web.resource.org/cc/DerivativeWorks&amp;quot; /&gt; &lt;requires rdf:resource=&amp;quot;http://web.resource.org/cc/ShareAlike&amp;quot; /&gt; &lt;/License&gt; &lt;/rdf:RDF&gt;