Agnieszka Figiel
blog.agnessa.eu
Kraków Ruby Users Group
Ruby on Rails
"Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern."
www.rubyonrails.org - Ruby on Rails official site
2005 David Heinemeier Hansson
opinionated software:"it’s a very pragmatic, very targeted
framework with a strong sense of direction. You might not share its vision, but it undeniably has one."
Outline
Design Principles MVC architecture Agile Development
Usability and Success Stories Community and Resources
Design Principles
MVC architecture Agile Development
Usability and Success Stories Community and Resources
Model - View - Controller
separate data (model) from user interface (view)
I Model
I data access and business logic I independent of the view and controller I View
I data presentation and user interaction I read-only access to the model
I Controller
I handling events
Database Persistance
I OR mapping
Active Record design pattern
I migrations
incremental schema management
I multiple db adapters
MySQL, PostgreSQL, SQLite, SQL Server, IBM DB2, Informix, Oracle, Firebird/Interbase, LDAP, SybaseASA
Full Stack Framework
I MVC suite
I built-in webserver
I default db adapter
I integrated logger
I AJAX, web services, email
I test framework
Convention over Configuration
I fixed directory structure
everything has its place – source files, libs, plugins, database files, documentation etc
I file naming conventions
e.g. camel case class name, underscore file name
I database naming conventions
table names, primary and foreign keys
I standard configuration files
e.g. database connections, environment setting definitions (development, production, test)
DRY - Don’t Repeat Yourself
I reusing code
e.g. view elements
I reusing data
e.g. no need to declare table field names – can be read from the database
I making each line of code work harder
e.g. mini languages for specific domains, like object-relational mapping
I metaprogramming
Design Principles
MVC architecture
Agile Development
Usability and Success Stories Community and Resources
Model - ActiveRecord
I conventions:
I name based OR mapping: mice db table ->Mouse class I primary key: auto-incremented numeric field called "id" I foreign key: "[singular_of_foreign_table_name]_id", e.g.
"cat_id"
I dynamic getters, setters, finders
dynamic means the existance of a field in db is enough to
manipulate it, e.g. dynamic getter like: mouse.name
I abstracted db operations - create, update, destroy, find, ...
possible to use raw sql, but usually unnecessary, e.g.:
Mouse.find(:all, :include => {:mouse_holes}, :conditions => "location = ’shed’",
Model - ActiveRecord
I support for basic entity relations (1:1, 1:n, n:n) with
dynamic accessors
backyard_mouse_hole.mice #=> Array of Mouse objects
I parametrised queries against SQL injection, e.g. find all
mice whose name is sth entered by the user:
Mouse.find(:all, :conditions => ["name = ?",
mouse_name)
I validators: an object won’t be saved in db unless it passes
all validation rules, e.g. uniqueness of a given field:
validates_uniqueness_of :login
I object life cycle callbacks, e.g.
before_create, before_save
View - ActionView
I multiple template types
I oldest and basic: erb (embedded ruby), similar to e.g. jsp I remote javascript templates
I xml templates
I easy reuse of view elements
I file inclusion – layouts, templates, partials
I multiple standard "helpers" – common html element generators (e.g. form elements, paginators)
I ridiculously easy AJAX integration – prototype,
Controller - ActionController
I all actions grouped logically in controller objects (actions
are public methods of the controller class)
I conventions
I name based url – action mapping e.g. url: myhost.com/mice/show/1
action: ’show’ action in MiceController, params: id=1 I name based action - template file mapping
e.g. action ’show’ in MiceController - template file app/views/mice/show.rhtml
I can be organised in an inheritance hierarchy
reduces code duplication and simplifies code
I action callbacks –
before_filter, after_filter, around_filter
I built-in mechanism of url rewrites – routes
Design Principles MVC architecture
Agile Development
Usability and Success Stories Community and Resources
Rapid Development
I built-in webserver
I generators – save the fingers
I scaffold – kick-off start
Debugging
I verbose log output
I breakpoint debugger
Testing
I test database + fixtures
I unit tests - tests for models
I functional - tests for controllers
I integration - tests for workflow
Agile Project Heartbeat
I test coverage - rcov
I continuous integration
I iterative db schema control - migrations
Design Principles MVC architecture Agile Development
Usability and Success Stories
Platform Independence
I win, lin, mac
I Apache, Lighttpd, mongrel
IDEs
I textmate
I vim
I RadRails, Eclipse + RDT, Aptana
I plugins for Idea, NetBeans
I SCiTe
Scaling
I it scales – a must-see slideshow about scaling twitter (600
req/s!): http://www.slideshare.net/Blaine/scaling-twitter I view caching I page caching I action caching I fragment caching I sql caching I memcached
I shared nothing architecture - multiplying application
Hosting
I http://wiki.rubyonrails.org/rails/pages/RailsWebHosts
I US - a variety of shared hosting offers
I Poland - poor shared hosting options hosted.pl
Success Stories
several ror powered high traffic sites
I http://twitter.com/ - community site
I http://www.odeo.com/ - music sharing
I http://www.43things.com/, http://www.43places.com/,
http://www.43people.com/
I 37Signals: BaseCamp, BackPack, Ta-Da List, Writeboard,
CampFire
Design Principles MVC architecture Agile Development
Usability and Success Stories
Books
I in English:
I ruby: "Programming Ruby 2nd Edition" (the Pickaxe) Dave Thomas, with Chad Fowler and Andy Hunt
I "Agile Web Development with Rails" Dave Thomas and David Heinemeier Hansson
I "Rails Recipes" Chad Fowler
I many, many more: http://www.rubyonrails.org/books
I in Polish:
I "Programowanie w j ˛ezyku Ruby. Wydanie II" Dave Thomas, Chad Fowler, Andy Hunt
I "Rails. Przepisy" Chad Fowler
I "Ruby on Rails. Wprowadzenie" Bruce A. Tate, Curt Hibbs I "Ruby on Rails. ´Cwiczenia" Michał Sobczak
Links
I main site: http://www.rubyonrails.org
I PL site: http://www.rubyonrails.pl/
I general mailing list:
http://groups.google.com/group/rubyonrails-talk
I wiki: http://wiki.rubyonrails.org/rails
I api: api.rubyonrails.org
I 74 Quality Ruby on Rails Resources and Tutorials:
http://www.softwaredeveloper.com/features/74-ruby-on-rails-resources-tutorials-050207/
Events
I Rails Conf
I Rails Day
I local communities & meetings
I Ruby on Rails workshops:
http://rubyonrailsworkshops.com/
pics:
http://www.midcoast.com/ holo/Seth%20in%20Thailand/pages/Rail%20tracks.html, http://mfrost.typepad.com/cute_overload/2007/05/this_site_is_dr.html