Fixing Shipcalc Module Bug is an Example of Overriding Drupal Forms.

April 23, 2008 | 0 comments

A customer on a newly launched Drupal e-commerce site I produced reported the following error:

Please enter a valid ZIP Code for the sender. (error -2147219498) usps configuration error. Please notify the site administrator.

Which occurred during the checkout process and only happened when a zip code contained a “+ 4″ code at the end.

Of course, I often find Google to be the best debugging tool of all, and I quickly found this post containing a workaround by Kenneth Bartlett that not only made it so I didn’t have to untangle the shipcalc module’s code, which would likely mean debugging Web Services calls to USPS, but is actually a pretty good solution in its own right I think.

The only thing I didn’t like about it was that it directly patched an e-commerce module file at modules/ecommerce/address/address.module. Whenever I use a piece of customizable software like Drupal (or Wordpress, osCommerce, etc.) I avoid directly patching both the core code and any third party modules, because this creates a maintenance burden for me when I want to upgrade the core software or an affected module, which could potentially wipe out these kinds of patches. I have my hands maintaining my own code, I don’t want to worry about modules I didn’t write.

Being Steve Jobs.

April 17, 2008 | 2 comments

I am reading The Second Coming of Steve Jobs by Alan Deutschman, and although the book was published way back in 2000, it was written at a time when Apple had already made a strong comeback, so I thought that it would still be a relevant case study of Job’s and Apple’s success.

A Potential Confusion When Converting HABTM Relationships to has_many :through.

April 10, 2008 | 0 comments

As someone relatively new to Ruby on Rails, I managed to confuse myself on one of my Rails projects recently when I decided to follow some very logical advice in Obie Fernandez’s The Rails Way that said that has_and_belongs_to_many (habtm) relationships were essentially deprecated in Rails, and that has_many :through was the preferred way to handle many-to-many relationships.

With has_many :through, the join table becomes a full-fledged rails model, meaning that you have more flexibility to extend the functionality of that model as your application evolves in the future–a very sensible best practice. So, I decided to convert an existing relationship that I had specified as habtm to has_many :through. I began to see errors that initially confused me, along the lines of NameError: Uninitialized Constant …. I had misnamed my join model and table because I was still thinking from the habtm perspective instead of treating the new model as I would any other model in a has_many…belongs_to relationship.