Randomize Web Images with JavaScript

This is documented in many other places on the Internet, but it can’t hurt to have too many tutorials. You can jazz up your web site with a bit of JavaScript to randomly insert images on your page. I’m doing this on my masthead, as one example. The first requirement is to build a list of images: Then write the code to select one at random: Finally, you need to set up the HTML to hold the image: The name=’myPic’ relates to the JS “document.myPic.src” declaration. The id=’frontphoto’ definition in the <img> tag is the CSS magic that sizes the image. And the ‘images/bg.gif’ is a placeholder image that gets… Read More

Continue Reading

De-clutter Your Rails Views, Use Partials For JavaScript SEO

If your Marketing or SEO guy is out of control (and when are they not?), you may be finding yourself stuffing insane amounts of JavaScript into your Rails views in order to track page referrals, conversion rates and other Google or Yahoo SEO analytic data. Not good from an esthetic standpoint. The solution is to use partials to partition the JavaScript SEO stuff off into a corner. Plus, it’s easier to reuse. Say you need to add some JS optimization code that looks like this: Just create a _google_opt_file1.html.erb file under app/views/shared and then call it in your view with This kind of SEO script typically goes right before the… Read More

Continue Reading

IE 8 Compatibility View

As a UNIX / Linux bigot, I don’t use Internet Explorer much. As a web developer, I need to test as many browsers as possible. The matrix for all the possible browser / version combinations is pretty daunting already, and adding the IE 8 compatibility view to the mix doesn’t help. If your customer complains of hosed web pages, check the configuration under Tools -> Compatibility View Settings, and have him / her turn off all the check boxes at the bottom of the form. References: Microsoft Blog Microsoft IE 8 Features Wikipedia

Continue Reading

Rails Time Extension Edge Case

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… Read More

Continue Reading

Ouch. Tricky Rails Multiparameter Bug In Attribute Writers

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 (i.e. Pay Pal, Authorize.net, etc.). So how do you handle this information? attr_accessor to the rescue. You can have something like this: Now you can work with the users credit card number (as just one example) without commiting it to the Subscription table. But – one thing you need is the card expiration date. You can get that information from the user in a drop down menu in the view: This is a multiparameter situation,… Read More

Continue Reading