Gotta Love Ruby and Rails

Ranges are a powerful feature of the Ruby programming language. I know this trick isn't new, but I was so thrilled that one line of rails code produced a hundred lines of HTML.

All I wanted was a simple drop down box / select list element with the numbers 75 to 180 (to be used as weights). At first I thought, blah, boring loop logic with some sort of incrementer. But, nope, not with Rails. Here's all I had to do.

<%= select( 'object', 'attribute', (75..180))%>

The "(75..180)" is the magic part. Its a Range in Ruby and Rails pops it right into the select element. Neeto!

XCache on Lighttpd

A few weeks back I added XCache to my LAMP stack for a little performance boost. I didn't notice any immediate gains even though my phpinfo showed that XCache was installed. After some further digging and a little oversight on my part, I found that you must change xcache.size in your php.ini to anything greater than 0. That setting basically allows XCache the memory it needs to do its job. I tried the default 64M and immediately things seemed to pick up. I also noticed that less resources were being used on my machine after this tweak.

Current stack:

  • Ubuntu Server (Dapper Drake)
  • Lighttpd
  • XCache
  • MySQL 5
  • PHP 5

Seems to be working very nicely.

Phoenix Rock n Roll Marathon

I was quietly reminded this past weekend that the Phoenix Rock n Roll Marathon is quickly approaching. Only 15 more weeks! Its a little too close to begin training for the full marathon, but I definitely have enough time to shoot for the half. I began training today using Hal Higdon's half marathon training program. This is going to be a blast!!!

Warped Theme Available for Download

The Warped theme port for Drupal is now available for download. An online demo has been setup for anyone who wants to check it out.

Thanks again to Jay from Six Shooter Media for the template.


New Drupal Theme Port

Six Shooter Media has released another great open source template called "Warped". Its a great standards basess css/xhtml design which will work great in Drupal. Give me a day or two to commit to CVS. It will also be available for download from my site until it gets posted in the Drupal themes section.

Rails' observe_field with :function and :on

I've been fiddling with the observe_field element in Rails using the :function and :on parameters. Basically, I simply wanted to execute some javascript when the onkeyup event fired for a text box. The Rails Documentation lead me to the two parameters that I needed:

  • :function, Instead of making a remote call to a URL, you can specify a JavaScript function to be called.
  • :on, Specifies which event handler to observe. By default, it's set to "changed" for text fields and text areas and "click" for radio buttons and checkboxes. Use this parameter to change the watched event to whatever you want e.g. "blur", "focus", etc..

However, the :on parameter didn't appear to work, and after some further inspection of the Prototype code, I found that the parameter that the Rails code was generating wasn't even being used in Prototype.js.

So, I've modified the Prototype code slightly, to make things work. Here are my changes.

Abstract.EventObserver = function() {}
Abstract.EventObserver.prototype = {
  initialize: function() {
    this.element  = $(arguments[0]);
    this.callback = arguments[1];
    this.trigger  = arguments[2];

    this.lastValue = this.getValue();
    if (this.element.tagName.toLowerCase() == 'form')
Syndicate content