Monday, April 16, 2012

2012-04-12: Ruby on Rails Presentation for the ODU ACM


Recently I was invited to present Ruby on Rails as a rapid Web application development platform at an ODU ACM meeting. I have divided the session into three phases: presentation followed by live example application development and Q&A. The example application was a simple RESTful database driven application to store attendees' record with several attributes of various data-types.

I started the presentation with an overview of Ruby language. Ruby is a fairly new general purpose multi-paradigm (including functional, object oriented, imperative and reflective) language, with syntax inspired by Python, Smalltalk and many other languages. Ruby is designed for programmer productivity and fun hence, its primary focus is human rather than computer needs. This philosophy goes very well with the rapidly changing client needs. Often by the time programers are done with the application development as per the specifications, the client's needs have already changed. Hence, Ruby is very suitable choice for Agile development.

Ruby was not originally widely adopted. But after the public launch of Ruby on Rails as a Web application development framework in 2005, it really took off and now it has become one of the most rapidly adopted languages by the programmer community. Ruby on Rails is a leading MVC (Model-View-Controller architecture) framework built on Ruby language. After the rapid growth and adoption of Rails, other languages like PHP and Python came up with similar MVC frameworks.


The slides talk about introduction of Ruby on Rails followed by various philosophies of Rails framework like:
  • Convention over Configuration for rapid development and ease of understanding, maintenance, collaboration and learning.
  • DRY (Don't Repeat Yourself) for better code organization and easier maintenance.
  • MVC (Model-View-Controller) for isolation of business logic from data and presentation.
  • RESTful for predictable human friendly resource URLs and machine friendly representations while conforming the HTTP standards.
  • Database Agnostic for seamless migration of the application data from one database engine to the other, be it a transactional database (e.g. MySQL, SQLite, PostgerSQL, Oracle etc.) or schema-less database (e.g. CouchDB, MongoDB etc.). Rails uses Relational Algebra for intermediate query building/chaining and optimization with the help of ARel Ruby library then translates the final query into SQL depending upon the underlying database engine.
The slides end with the Rails application code organization followed by additional resources to learn more about Ruby and Ruby on Rails and introduction to some free and paid hosting solutions.

The presentation was followed by an interactive Ruby exploration session (using IRB) and a live application development demo. In the demo application I started from scratch and generated rails skeleton using nifty rails command. Then I walked through the generated directory structure and described some important files and folders. Using another handy scaffolding generator command, I created a resource with various attributes of varying data-types (including string, date, text and boolean etc.). Then I ran the migration to setup a database as per the resource description and started the development sever (a lightweight web server resides in every rails application by default). Then I showed the audience how magically those couple of commands have created all the pieces and presented with a simple, automatically generated HTML (CSS styled) interface for listing resources, showing a single resource, form for creation and edition of the resource and deletion link with a confirmation prompt. Then I briefly walked through some of the generated code and showed the audience how to customize the generated code.

After adding some records in the application, various presentations of the resources (like XML, HTML and JSON) were shown while explaining the RESTful URIs. I quickly mentioned Git distributed version control system for deployment on Heroku.

I didn't talk about environment setup and configuration as the time was limited. But I mentioned some resources that provide great details of all these. I also didn't go into details of various features of Rails like validation, authentication, model association etc. because it was an introductory walk-through presentation and the audience was mainly undergrads.

Thanks for the reading. I have these chocolates to share with you that I got as a token of appreciation from the organization chair. :-)


Useful links and resources:

--
Sawood Alam