Rails has some great generate commands and a whole lot more!

If you’ve played with Ruby on Rails you’ve likely used script/generate to scaffold a simple CRUD application (including controller, views, helper, database fixtures, unit test, and functional test) as follows:

ruby script/generate DomainModel Controller

In my side project to learn Ruby I’ve grown very attached to using script/generate to put the rough pieces in place for me and then fill in the details. I really like that unit and functional testing are core to the approach instead of an afterthought or 3rd party library that takes a lot of work to integrate. I write much better functional tests in Ruby because it’s so easy, whereas in Java with the whole httpunit/cactus/cargo approach is a lot more work!

Anyhow, as I started playing with web services and email I was pleasantly surprised to discover I could also use the same simple approach to generate web services using Action Web Service and email integration with Action Mailer as follows. Need email confirmation when a user signs up for a newsletter as well as a system to send the newsletter:

ruby script/generate mailer Newsletter confirmation send

How about a web service to let others get the most viewed blog posts today or for the week:

ruby script/generate web_service BlogService get_top_blog_posts_today get_top_blog_posts_for_week

Need a controller that accesses a web service, why bother with generating client stubs that need to be maintained in source control when you can just start coding against the webservice:

class MyWeatherReport < ApplicationController
web_client_api :weatherforecast, :soap, “http://somesite/forecast/api”

def forecast
@forecast = weatherforecast.get_todays_forecast(@params[‘zipcode’])
end
end

The more I play with Ruby on Rails the more impressed I am. It’s a fairly flexible environment that really seems to have it all but it’s ideal use in my opinion is for greendfield projects that can do it right from the start. If you’re looking at porting your site from C++ to the latest greatest thing but need to keep a lot of old legacy code running against a poorly designed database schema it may not be the right fit.

That said I think Ruby on Rails really is the next great thing. I haven’t seen anything else that provides such a simple, elegant, and comprehensive solution to web development that you can get up and running on so quickly! It has ORM, MVC (supporting components, partials, page decoration), the best domain model validation framework out there, built in and very easy to use AJAX support, unit testing (with database test fixture loading), functional testing, AOP style interception, web services, email integration, you name it… (just don’t name static typing ;-)).

If you’re looking to learn more about Ruby on Rails I can’t say enough good things about Dave Thomas and David Heinemeier Hansson’s Agile Web Development with Rails, it’s one of the few tech books I’ve read cover to cover. It’s so well organized I generally find it quicker to lookup a solution in the book than to hit the web. Needless to say I’m really enjoying learning Rails!

This entry was posted in Ruby. Bookmark the permalink.