Posts Tagged ‘Ruby’

Rails Time Extension Edge Case

Sunday, January 31st, 2010

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

Thursday, January 28th, 2010

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

A New Look for the Web Site

Tuesday, November 10th, 2009

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”)

Wednesday, October 21st, 2009

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

Changing IDEs

Saturday, September 5th, 2009

I have been bouncing between the RadRails and NetBeans IDEs for quite some time now. I like them both a lot, but I have not been able to make RadRails Test::Unit work 100%… Continue reading

Fun With Regular Expressions

Thursday, August 20th, 2009

If I wrote code all day, every day, I’m sure I could become really good at manipulating regular expressions. The obscure syntax is sort of Zen-like with a large dose of Perl obfuscation-fu. A one-liner… Continue reading

Watir on Windows XP – Installation

Thursday, May 28th, 2009

Watir – Web Application Testing in Ruby – I’m thinking about adding this as part of my standard Rails integration tests. I like the idea of capturing keystokes that a user might actually run. Plus… Continue reading | 2 Comments

Ruby 1.9.1 (Entry 1)

Wednesday, April 1st, 2009

I installed Ruby 1.9.1 from the Ruby site. I did the default “configure ; make ; make test ; make install” dance as root using gcc 4.1.2. This puts all… Continue reading