ruby on rails

Hardcore Hosting

I've been through the gamut of web hosts. I started on a shared host when I was using ASP.NET with Microsoft and SQL Server. The site worked and support was ok, nothing to brag about. I soon found out that my host couldn't support what I was wanting to do (host an open-source CMS called DotNetNuke) so I soon switched to another host that would. Things worked fine, but my sites always just seemed a bit sluggish.

I soon learned that if I wanted things to work exactly how I wanted them, I had two choices: 1) Buy a server and all the software that goes along with it and house it in a colocation facility somewhere (too expensive for me at the time), or 2) find a dedicated server hosting plan where I can do what I wanted to the server to make it run optimally for what I was doing. So, I chose option 2 and found a local company that, I must say, did a great job - CrystalTech.

Garbage Spitting RJS Templates

I was going through some controllers today and AJAX'ing several forms by replacing my start_form_tag with form_remote_tag. One of the actions that my form was submitting to fell through to an RJS template that had a simple replace_html directive. The weird thing was that this particular RJS was spitting out garbage on my page. It was showing special characters like line feeds, carriage returns (\n, \r) etc. all over the page.

After about an hour of fiddling with this I finally found the problem. I mistakenly put an :update attribute in my form_remote_tag. Somehow this was causing a conflict with the RJS template calls. After removing the :update attribute, everything worked fine.

Hopefully someone with the same issue stumbles across this early on in their search.

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!

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

Desert Schools FCU

Vallejos Enterprises

Brighton Park HOA

DHL Logistics & Supply Chain

Unicorn Financial Services - MyUnicornAccount.com