Rails Tip No.1: Making datetime_select more appointment-friendly

May 5th, 2008

This is the first of what I intend to have as an ongoing list of Ruby on Rails programming tips. These are as much for plugging my own memory holes as they are for the general Googlejuice. Each should be a brief illustration of some technique on how to accomplish something in Ruby on Rails - probably in the form of a short code snippet with explanation. I should preface this all by stating that I am by no means an expert on Rails - I’ve been using it since late 2007 - so any urge to expound upon these thoughts by the Lightning Rails Ninjas™ out there would be most welcome indeed. Please feel free to comment.

The first one I’d like to present is how to get the datetime_select helper method to be slightly more user-friendly for your garden-variety appointment form.

Consider you have a form set up already for booking appointments. You may have used datetime_select for the start and end times for your form. The default implementation gives you the current date and time as defaults, and each item is rendered as a select menu.

But rarely would you want to do a new appointment on the same day and at at 12:06 PM, right? More often those things are scheduled at least a day in advance, and on the :00, :15, :30, and :45 minute marks. Or at the very least, having five minute increments for the minute menu should help pare down the options and make things simpler. Here’s an example of how something like this could be accomplished:

< %= f.datetime_select :appointment_start,
                       :default => 24.hours.from_now,
                       :minute_step => 5 %>

For the above example, we have a datetime_select form helper for the appointment_start column in our database. Simple enough - this is probably how a default code snippet would look from say a scaffold generation. Following that, we’ve passed a couple of extra bits of information to our helper - a default date and time, and a specification on how we should increment the minutes column.

:default => 24.hours.from_now does exactly what you’d expect - sets the default date and time for all the menus ahead one day. You could just as easily say three days from now, four years from now, and so on. And :minute_step => 5 gives us the five minute increments that we want. Set it to 15 if you’d like to pin it down to the :00, :15, :30, and :45 minute marks. Simple!

Updated and Upgraded

April 7th, 2008

Migrated to WordPress 2.5 this evening, which was a nice and painless upgrade. In the process I discovered an old and useless plugin that had been left turned on, and disabling that pig made my whole site so much faster - it was killing me to find the reason why this thing was so pokey before and I can’t believe I didn’t see it before.

The new admin interface designed by Happy Cog is instantly tons more usable. Everything else seems to work fine, including the iPhone happiness.

Poppies

April 5th, 2008

It is a pretty planet on which I live:

Poppies

Grabbed this shot up on Mt. Diablo today. The wildflowers were off the hook. Really gorgeous out there lately. The poppies were predominant, dotted with other spots of purple, white, and yellow blossoms here and there. The flowers ran rampant down the hillside:

Poppies

And then in this perfectly bucolic scene, we have the 3 year old, making faces:

My crazy son, with poppies.

Mouth

Sigh… ;-)

LibraryThing

March 11th, 2008

LibraryThing is one of my favorite web 2.0 sites. As I mentioned in an earlier post, it is Flickr for bookworms. One of my missions is to always have a book that I’m actively reading - something I keep around with a bookmark in it, reading it whenever I get a chance. Turns out LibraryThing is a great way for me to keep a pulse on all of it, if nothing else than to have a visual reminder of what it is I read so that I can stoke some memory of the details for the things I’ve been learning along the way.

So lately they’ve added a few new features, and one feature I particularly like is that they added a status feature to indicate what is currently being read. Another feature I discovered recently was the ability to post a list to my weblog, as I’ll do here (sorry non-JavaScript-enabled clients:)

As you can see, not a lot of this is fiction - just technical and theoretical mumbo-jumbo for the most part. It is my hope someday to get over the technology goals I currently have, and start reading something more fun, like some more Marquez or Lorca.

Review: Green’s Gluten Free Beers

March 6th, 2008

Green's Beers

Beer tasting is back. Yesterday I found Green’s Beers in stock at the local BevMo. They had three of their varieties: Quest Tripel Blonde, Discovery Amber, and Endeavour Dubbel Dark. At around $5.50 per 500ml bottle, this is not cheap stuff. But as a deprived enthusiast of the craft ale, this is worth the experiment.

Why this is huge: I used to design my after-hours business travel around looking up whatever highly-rated microbreweries and brewpubs might be in the neighborhood, sample the local taps, and write little reviews of each of ‘em. I loved tasting ales across the country - it was a simple and fun hobby, and gave me something to do while having to spend time away from home.

Then I started getting sick with celiac, and when the doctor told me I had to avoid wheat, barley, and rye for life, the only thing that went through my mind was “barley… barley… holy crap!! That means no beer!!!!”

Thankfully I seem to live in a time where gluten-free ale is an emerging market.

Quest Tripel Blonde

Monday: I miss IPA the most. Tripel Blonde sounded most like the description I was looking for, so trying this one first was irresistible. The beer pours clear but then seems to cloud up a bit, with lots of carbonation, and definitley has a light blonde color to it. The aroma was slightly floral, but not too sweet. Taste is great, with plenty of mouthfeel and a nice crisp taste. Definitely a good beer. I could drink this any day. I could use a bit more hops, but I said this about just about every beer I ever tried. OK this pint of beer is listed as being 8.5% ABV, so I might have an interesting time finishing up that ActionScript project I was working on this evening.

Discovery Amber

Tuesday: This beer pours in a nice rich amber color as advertised. There is a distinct hoppy aroma and the character is very ale-like. The beer really tastes damn good actually - lots of mouthfeel similar to the Quest, but I’d venture to say this one tastes even closer to some of the pale ales and amber ales I was used to in the past. If you had to give me my choice between this and the Quest, I’d probably pick this one. In fact, this is the first beer I’ve had since going gluten-free where I felt like there were absolutely no compromises. ABV is 6%.

At this point my recommendation to Green’s is: Open up a North American plant and start distributing these like mad. The Discovery Amber would stand up against any barley-based craft ale.

Endeavor Dubbel Dark

Let me just preface this section by saying that all of the American gluten-free brews I have tried thus far do not come even close to the three beers I have just tried from Green’s. Redbridge is my favorite of the American set, and it is not bad, but these three Green’s varieties are really outstanding.

Now, the dubbel dark was everything I’d expect from a dark beer. Had a similar flavor and character to many of the dark brews I’ve tried when I toured Germany and Austria way back when. Had a dark, malty, almost nutty flavor. Delicious. I transitioned away from dark beer in favor of pale ale over the decade before my celiac diagnosis, but this beer could easily get me back into it. This reminds me of why I liked dark beer in the first place. Note: This is nowhere near a stout, nor should the name ‘dark’ imply stout. It is strictly in the double bock variety and a damn good specimen.

My advice to Green’s is: Having cheap access to Greens would be a reason for me to move to the UK. But I’m sure you guys don’t want that. I would tarniish the place and lower property values. Instead, open up manufacturing in North America, get the price down to something reasonable, and distribute these without reservation. This is the first beer label I’ve tried that really gets it right. Redbridge is great, and way cheaper, but Green’s has the quality part of the bargain hands down.