Dave Thomas runs The Pragmatic Programmers company with Andy Hunt. He and Hunt co-authored The Pragmatic Programmer and Programming Ruby (AKA ‘The Pickaxe Book’). Mike Clark is co-author of Agile Web Development with Rails, author of Pragmatic Project Automation, and co-teaches Pragmatic Studio: Ruby on Rails.
This tutorial was in one of the larger rooms, and was (predictably) very full. It was mostly just a solid, step-by-step intro to Rails — naturally including the standard Rails demo of rapidly building a basic application. Beyond the basic introduction of a Rails app structure (i.e., what files go where), and how to build a Rails app, they also went into a few other areas of Rails development that I found interesting:
Migrations provide a procedural way (in Ruby code, natch) to create and modify your database schema. This is useful if you want a database-independent way to maintain your schema. They are also be helpful in keeping multiple developers in sync with structural changes to your database. Migrations are also reversible, so you can undo changes if you don’t like them.
Model finder methods
They demonstrated how to combine different arguments for
find. Seeing some of the different ways to do it is helpful for someone like me who tends to use
find_by_sql as a crutch.
Rails is known for being extremely good a managing simple data models, including basic one-to-one, and one-to-many relationships. Now you can deal with slighly more complicated setups a bit better. The original way to deal with many-to-many relationships was a simple join table that doesn’t show up in your model anywhere. The newer way is with something called a ‘through association’ which is an object you actually put in your model, where you can also hang meta-data about the association (e.g. an Order has many Items, and each Item association has a UnitPrice and Quantity).
It’s super simple to convert your results set to XML by giving your template an ‘rxml’ extension, which uses a programmatic builder template instead of the normal mix of markup and RHTML tags.
Simply RESTful is a Rails plugin for routing that maps the HTTP ‘verbs’ for REST-style communication to the URL paths for the common CRUD actions in Rails (e.g. POST = ‘create’, PUT = ‘update’, DELETE = ‘destroy’, etc.).