Rails: The Demonstration
I often criticize products from the big vendors like IBM, Microsoft and Oracle for what I call the “New Coke Effect”. As retold by Malcom Gladwell in Blink, Pepsi introduced blind taste tests in the 80s. They beat Coca Cola by a big margin. In order to regain the advantage, Coke developed “New Coke”, a product that was optimized for the blind taste tests. It tanked. Totally. It tanked so bad that coke had to have the words “classic coke” prominently on the label until 2002.
The problem is that a blind taste test is not the same as drinking a whole bottle. People prefer sweet tastes when they just take a sip, but not when they want to finish the glass.
A lot of visually oriented software development tools are similar: They have been optimized for a 30 minute demo in front of a crowded auditorium. Sadly, many of these products are an active obstacle when you want to “finish the glass”, that is, deliver working software into production. Ruby on Rails is different: It looks great in a demo, but it take the whole software development life cycle into account. These two facts put together is why I recommend it so much these days. (Shameless plug: If you’re located in Oslo, and would like an introduction to Ruby on Rails: Feel free to get in contact with me). For a full tutorial on Rails, I recommend Rolling with Ruby on [Instant]Rails, by Curt Hibbs and Bill Walton.
The Demonstration
This week, I showed a client how to use Ruby on Rails to get started developing web applications. I felt the workshop was a fruitful one. None of the people in the room (except me, of course) had any experience with Ruby on Rails or Ruby, and some of the audience had not worked with programming at all for several years. In spite of this, everyone was able to understand how the application worked, and how everything fits together. This is what I find to be so fun about demonstrating Rails: There are no hidden tricks. I can install everything on a provided computer and I can explain how all the pieces fit together. I can explain how to address deployment, database upgrades, layout issues, AJAX, REST-webservices, security, and scalability. This is not a magic trick to be waved in front of an audience and they quickly hide behind your back. In a matter of a few hours, we were able to demonstrate, discuss and explain:
- Install the necessary software (Ruby, MySQL, and Rails itself via
gem install rails
. Alternatively, we could’ve used InstantRails) - Create an explore a working, simple “hello world” web application
- Use Ruby on Rails’s Migration and Scaffold to create a database table (
ruby script/generate model service_provider name:string description:text registration_date:date
) and the web pages to create, display, update, and delete entries in the table (ruby script/generate scaffold service_provider
). Rails comes with scripts to create the tables (rake db:migrate
), and load pregenerated (but editable) test data (rake db:fixtures:load
). - Create and explore a bidirectional one-to-many relationship between ServiceProviders and Customers with has_many and belongs_to
- Implement a mock-login scheme using sessions. Our login-action lists all the service_providers (using a select list). Yeah, I know it’s lame, but implementing passwords takes time, and doesn’t really prove anything.
- Restrict which Customers a ServiceProvider can see and modify (by using a before_filter and using
session[:service_provider].customers.find
instead ofCustomers.find
,session[:service_provider].customers.delete
instead ofCustomers.delete
andsession[:service_provider].customers.build
instead ofCustomers.new
) - Implement some validation rules
- Explore (but sadly, not demonstrate) deployment options using Capistrano
Comments:
Niraj Manandhar - Apr 26, 2007
Dear sir
Do you think that the word scalability goes together with the dynamic languages like Ruby or PHP.
Recently i have been hearing and doing JRUBY Can you guide me on how can i develop a rails application in JRuby and run that application in Jetty or any JavaEE web container.
Last thing is can you tell me where do i use blocks in more partical way rather than listing element of an array
Johannes Brodwall - Apr 29, 2007
Good questions, Niraj
Rails have no problems with scalability for most usages. See RailsExpress for lots of tips on how to make it scale. My impression is that people are running Rails with 100s of hits per second without too much effort.
JRuby has just recently come to a state where it can run Rails. I would wait a little with that. Unless you absolutely MUST use a J2EE-container, I think you’re better of with Apache/lighttp + Mongrel + Capistrano, anyhow.
For some cool usages of blocks, see Jamis Buck’s blog, BDD from Luke Redpath, and hopefully soon, rbehave from Dan North. For the underlying justification, see Artima’s interview with Matz.
Marius Mårnes Mathiesen - Jun 18, 2007
As this thread is a few months old and a lot has happened since, here’s a small update. Jruby is now in 1.0, and runs Rails perfectly. It actually outperforms C-ruby, and one of the really cool things that has spun off it is the Gold spike plugin, which lets you create WAR files from a standard Rails project. This war includes everything needed to run your Rails app inside a java app server, including JRuby itself, any JDBC drivers (unless, of course, you prefer the pure Ruby database drivers), the java ports of OpenSSL - the works.
Gold spike probably isn’t ready for production use yet, though, but Sun is working hard on it. As for the general readiness of Jruby on Rails, Thoughtworks recently announced RubyWorks (http://studios.thoughtworks.com/rubyworks) an offering where they provide support for Jruby/Rails apps.
My recommendation is to give JRuby on rails a try. Try running Jruby with mongrel (the java port) and run it the traditional way behind Apache if you like. I’m sure you’ll be satisfied!