Amidst all the recent non-technical work that I have been doing, I have managed to plug myself back to the wonderful world of Ruby on Rails. I have written a number of posts regarding my experience with Rails 1.0 before in my blogs. Having made a recent decision to focus my engineering skills in Rails 2.0, I thought it would be a good time to continue that Rails 1.0 legacy that I left off.
The first thing that caught me while doing Rails 2.0 was
Scaffolding. Being as lazy as I am when it comes to programming, I loved scaffolding to bits in Rails 1.0. I like the idea of being provided with scaffolds and build the software inside out.
I was surprised when my usual
?>script/generate scaffold model_name controller_name actions
did not work. It turned out that the new way to do scaffolding in Rails 2.0 is the following way :-
?>script/generate scaffold modelName field_name:field_type
It’s that simple!
For example, ?>script/generate scaffold User name:string role:string will generate a User model with the attribute of Name and Role in it. The screen shot below shows the physical database model created after migration ( ?>db:migrate) is done. It’s filled with stub data created with the scaffolded interface.
That single line of command generates the usual CRUD operations associated with the model. Furthermore, scaffolding also creates the usual methods in the controller that responds to both conventional + REST style information access!!! For instance, the below screenshot shows the XML returned when I did a /users/1.xml in Firefox.
I will be playing more and more with Rails 2.0 in the coming days.
Stay tuned!!!