, ,

I have had the chance to work on a Rails project this December and learned quite a lot in the process. My earlier reading and trying out some sample applications surely helped. However, doing a real life project gave more insights and knowledge about the framework. So here I am, trying to document some of those learnings, niceties and weirdos (in no particular order).

Rake is cool! One of the gotchas is that the command “rake -T” displays only those tasks that have descriptions. Also, found a nice way to pass parameters to rake tasks here – the parameters need to be passed are listed next to the task name as below. When this idiom is being used, the usual way of specifying the dependency tasks does not work. We need to use “:needs” explicitly and specify the dependencies. “args” is a hash of all the parameters that are passed to the task.

task :truncate_table, :db_name, :tbl_name, :needs => [:environment, :load_config] do |t, args|

Providing a drop down of time zones is so simple using the time_zone_select helper method. The priority_zones option is a nice way to specify some time zones up front so as to avoid the hassle of going through the entire list.

There is also a country_select plugin that gives a drop down of countries. Seems that this functionality was available earlier in Rails and later extracted out as a plugin.

All files in config/initializers are loaded at server start-up. Application level constants can be written in a file, say, constants.rb and saved in this folder and accessible from anywhere in the application.

One of the things that tripped me early on is the need to restart the server for any changes done in the modules in ‘lib’ to take effect.

Thanks to K, came to know about gotapi and used it extensively!