Rails Time Extension Edge Case

January 31st, 2010  / Author: cwl

I love the extensions that Rails has for the Ruby Time object (see ActiveSupport::CoreExtensions::Integer::Time) – you can do calculations like Time.now + 1.month, (4.months + 5.years).from_now, and other cool things.

In my last post, I mentioned working with an application that uses a subscription service. One of the things I want to do is send the subscriber an e-mail when the current subscription is about to expire. (I am not comfortable with the concept of auto-renewal; customers should have the right to “opt in” on the continuation of a subscription. Just personal preference.) So I set up a cron job that tests subscription expiration dates. Here’s the one that checks a month in advance:


next_month = Subscription.find(:all, :conditions => [ "subscription_expires_on = ?", (Time.now + 1.month).to_s.split()[0] ])

With a test case subscription expiring on Feb 28, e-mail went out correctly on Jan 28. And also on Jan 29, Jan 30 and Jan 31. Ooops! My reminder has turned into nagware. What I really want is:


next_month = Subscription.find(:all, :conditions => [ "subscription_expires_on = ?", (Time.now + 30.days).to_s.split()[0] ])

Live and learn.

Ouch. Tricky Rails Multiparameter Bug In Attribute Writers

January 28th, 2010  / Author: cwl

I’m building a web site with a subscription-based payment system using ActiveMerchant. The first rule is, don’t put any user financial information into your local database, just pass the user input to your payment system… Continue reading

Multiple Rails Apps Under Passenger

December 30th, 2009  / Author: cwl

My development server is on a home LAN behind a firewall, and I don’t want to make it a DNS sub-domain. I have directed my router to issue fixed IP addresses through DHCP, so I… Continue reading

OpenSolaris Under VMware

December 17th, 2009  / Author: admin

OpenSolaris looks pretty cool, so I’m giving it a spin as a VMware Virtual Machine. The trick is to set up the new VM as a Solaris 10 system – that wasn’t obvious to me… Continue reading

Rails and PHP under Ubuntu Apache

December 15th, 2009  / Author: admin

I have Ubuntu 9.10 (aka Karmic Koala) running on my laptop. It’s rapidly becoming my portable development machine, so I set up the Rails environment right away. I have decided to add PHP to the… Continue reading | 2 Comments

Close Enough for Now

November 24th, 2009  / Author: admin

I think the format is a bit better. On to other things…

- Changed the image to something I own

- font-family: Verdana,Tahoma,Arial,sans-serif;

- Changed text color to black

- Changed… Continue reading

Theme Thrashing

November 19th, 2009  / Author: admin

I’ve never been entirely satisfied with the way my blog looks – it still feels “hard to read”, and I’m not sure how to fix that, except to experiment with some other two-column, fixed-width WP… Continue reading | 1 Comment

VMware Server 2.0.2

November 19th, 2009  / Author: admin

The latest VMware Server version is 2.0.2, released on October 27 of this year, so I thought I would give it a spin. The downloads are available as RPMs, so that was the obvious… Continue reading

A New Look for the Web Site

November 10th, 2009  / Author: admin

My mostly static web site was hacked together about 5 years ago with straight HTML tags using the XEmacs editor. To say the least, it was starting to look pretty frayed around the edges, not… Continue reading | 1 Comment

Rewind Ruby 1.9.1 (or “Put The Candle Back”)

October 21st, 2009  / Author: admin

I updated all the gems for my current Rails development project that is using Ruby 1.9.1. This also included an upgrade to Phusion Passenger 2.2.5. Then I upgraded to Ruby 1.9.1-p243, which promptly crashed… Continue reading