Rails:join table name
I just came across the naming convention for a has_and_belongs_to_many relation’s join table.
If you have tables products and categories, which have a many to many relationship, a product can belong to many categories and a category can contain many products. What would you name the joining table, products_categories or categories_products.
Rails convention says use categories_products.
Rails assumes that a join table is named after the two tables it joins (with the names in alphabetical order). If you use some other name, you would need an additional declaration.
Unless there is a very compelling reason to do so, one should stick with the convention.
Reason: For maximum productivity don’t go against Rails’ philosophy “Convention over configuration”
Tags: rails, ruby on rails, convention over configuration, join table names, has_and_belongs_to_many
That time of the Year
It is that time of the year again…. when one should take stock. For me 2005 was the first time that i had set yearly goals [ read a new year resolution].
I had set many goals. They covered various fields like health, work, learning japanese, learning to swim, teaching Kuhu[my daughter] etc …
I did not achieve all that I had written down. But I made a lot of progress in all of them.
At the end of the year, I am in a position to say that for me this year was a lot better than the previous years… cos i had set some parameters to measure my performance against. I had those goals guiding me throughout the year, as i used to check my performace against them, every monthend.
I came across this quote today by Karen Lamb :
A year from now you may wish you had started today.
I am happy that I had started doing some things last year. At the same time, I want to add a few more this year.
I will spend a few hours tomorrow to write my goals for the year 2006.
I want to do so much… and breaking all of that down into smaller tasks makes it a lot easier to achieve.
Ryze Christmas Mixer
Attended the Ryze Christmas Mixer, at Park Balluchi on Saturday, 24th Dec, along with Pooja and Kuhu.
It was my first mixer, though i have been on ryze for a year and a half.
It was good to meet a mix of people, from various fields, software, travel, KM, media, lawfirms etc.
Had some interesting discussion with people about networking as such, pros and cons of online networking, maximizing benefits of online networking etc.
Made a lot of friends. Pooja and Kuhu also enjoyed a lot.
Kuhu got to see a lot of deers, since the resturant is located inside the Deer Park.
Here are some pictures from the mixer.
And yes the food was great :-)
Tags: none
The Stockdale Paradox
I am reading Jim Collins’ Good To Great.
While reading Chapter 4. Confront the Brutal Facts (Yet Never Loose Faith), I came across the stockdale Paradox. I remembered having read about it earlier.
I googled for it and found the link .
I had read this blog post a couple of months ago, which applied Stockdale paradox to the startup phase.
The Stockdale Paradox, reinforces my belief in Perseverance and Patience. When i started my company, the only advantage (read USP) we had was “cheap programmers”. But I wanted to do more than provide services to companies because we were cheap. And gradually, at the cost of refusing lame projects, we have been able to build niche areas. I had to refuse projects, which would have added to the numbers, but would have not given the joy of programming which me and my fellow programmers now enjoy at vinsol.
This transition at vinsol, involved not only The Stockdale Paradox, but also the Hedgehog Concept, which Jim Collin discussed in Chapter 5.
I recommend this book, very strongly to all. It is a must read for Indian companies who want to rise up the value chain [I do not say that we have done so, but are better placed than where we were an year ago.]
Rails: Automatic Time Stamping
I tried this with mySQL. Should work with other databases too.
If you have columns named “created_at” or “updated_at” of type datetime in your database table,
Rails will automatically insert the value of now( ), in the column “created_at” when a model corresponding to the table is saved in the database. Similarly it will automatically update the value of the column “updated_at” to the value of now( ), when a model is updated and saved to the database.
“created_on” and “updated_on”, of type date, display the same functionality.
One of the basic Rails philosophy is “Convention over Configuration”, meaning that rails has sensible defaults for a lot of aspects.
If the programmer follows these naming conventions a lot of functionality in the application gets built-in by default.
Rails: avoid empty lines in generated html
Normally embedded Ruby code (Erb) in views that does not generate any output, leaves empty blank lines in the generated HTML code. These are embedded ruby lines in rhtml files which begin with < % and not <%=.
To avoid generating these empty blank lines, end the embedded ruby code with -%>, the others will be ended as %>. The extra minus sign (-) at the end, will suppress the blank lines.
Tags: rails, ruby on rails, Erb

