My little rails app is complete

The Rails app that I was working on a couple weeks ago for work is finally complete and in the hands of users. A couple higher-priority tasks kept me from getting back to it until yesterday, and the final push towards release was fantastically ugly.

For legacy reasons, I need two of my app’s controllers to use HTTP basic authentication, not form-based authentication. HTTP authentication with Rails isn’t well documented, but the ”teenage mutant ninja hero coders” have an example that works just fine with webrick. Unfortunately, it completely fails with Apache for reasons that weren’t particularly clear. It’s fairly well-known that Apache blocks CGIs from seeing HTTP authentication headers, but none of the workarounds that should have worked with Apache 1.3 (mod_rewrite, fastcgi, etc) actually worked.

In the end, I ended up upgrading to Apache 2 with FastCGI, and it worked flawlessly. Er, except the CGI variable that I was looking for went from being called HTTP_AUTHORIZATION to Authorization, so I had to tweak application.rb a bit.

Posted by Scott Laird Thu, 14 Apr 2005 21:59:54 GMT


Rails success

My little Rails project at work is starting to wind down finally. I’ve been heads-down on this thing for almost a week, but it seems to be worth it–I have a nice UI around my database, along with a clean schema to replace the hacked-up one from the previous design. I have 8 models, 9 controllers, and 40-some views. Including tests and documentation, I currently have *90* files open in xemacs, a personal record.

Of the 4 days I’ve spent on this, at least one full day was lost to bugs in Rails that I had to find workarounds for. Probably another day was spent searching for examples and documentation on specific Rails features and generally learning how the system fits together. The remaining two days were divided between database/code design (there are some weird controller issues for this application) and HTML design. It’s been years since I last threw together anything more complex then a Movable Type theme, so my web-design skills were years out of date.

All things considered, 4 days doesn’t strike me as amazingly fast for this project, but I doubt that I could have been much faster using any other framework. The big thing that’s impressed me with Rails is the amount of polish that I’ve been able to put into this in a very small amount of time–things like pagination and live searching were nearly trivial to implement. With a bit of practice, I suspect that I could churn out similarly-complex applications in a little over a day, and that would be just astounding.

Posted by Scott Laird Thu, 31 Mar 2005 01:48:38 GMT


Another run at Rails

I’ve started to pick up Rails a few times, always to be interrupted by something–usually either a missing feature that I really needed, or a change in project priorities at work. I finally sat down with it today in an attempt to finish a little project that I’ve been avoiding for months at work.

It was all going well until suddenly one of my classes stopped working right. My Host class belongs_to my Group class. At one point this afternoon, host.group stopped working from inside of my web app. It worked perfectly with the unit tests, but I got a method undefined exception whenever I tried to access the group method on a Host object. Here’s a snippet of the code involved:

class Host < ActiveRecord::Base
  belongs_to :group
  belongs_to :customer
  has_and_belongs_to_many :messages, :order=>"id"
end

class Group < ActiveRecord::Base
  has_and_belongs_to_many :packages, :order=>"pkgorder"
  has_many :hosts

  validates_length_of :name, :maximum=>40
  validates_format_of :name, :with => /^[-0-9a-zA-Z.]+$/,
    message=>"may only contain letters, numbers, ., and -"
end

These two classes were in their own files, as generated by Rail’s generator script. Can you see what’s wrong? The line right above end in the Group definition should start with :message, not message. That missing colon in group.rb broke the Host class, but only when it was used after Group was defined. So the unit tests worked, because they tested each class separately, but it failed in a bizarre way when the two were used together.

Things like this make me wonder if maybe Rails isn’t getting just a wee bit too clever for its own good.

Other then that, though, it’s been working great. I’m spending too much time searching the Rails docs for help, but I’m moving right along.

Posted by Scott Laird Fri, 25 Mar 2005 08:53:41 GMT


The Blog Upgrade question strikes again

I installed Movable Type when I first started this blog, but I’ve been itching to change for months. A small part of that itch is Movable Type’s new pricing model, but it’s really more then that. I have a number of needs that MT isn’t really filling, and I’d like to move to something that works better for me.

The big problem is that I can’t find anything that’s quite right. I looked at Drupal for a while, but there are a few things with it that I just couldn’t cope with:

  • It’s a much bigger system then I really need, with a lot of complexity.
  • It’s written in PHP. If I could treat it as a black box, I wouldn’t really care, but I couldn’t because…
  • It’s essentially hard-coded to need MySQL. In theory, it’ll work with PostgreSQL, but I fought with it for days without actually getting it to work. There were a number of deeply-embedded MySQLisms in the code that I just couldn’t fix, even after digging into the code for a while.
  • PHP’s SQL code is too scary to look at. While the core of Drupal goes to great lengths to prevent SQL injection attacks, a number of add-in modules looked pretty clueless. In addition, all of the SQL code is built up using command = 'insert into foo (a,b) values ("'+value1+'","'+value2'");'-style commands, which are inherently ugly and prone to problems. I really prefer the Perl (and Ruby) DBI version: insert into foo (a,b) values (?,?), where you provide value1 and value2 as parameters to the DBI execute function.
  • Template modifications are a royal pain compared to MT. Out of the box, all of the templates used HTML tables, unlike MT’s clean CSS-only templates.

Now, if I was setting up a big community site, none of these would really matter to me. I could spend a couple weeks on templates. Heck, I’d expect to spend a while tweaking things until they worked right for me. If I was doing this from a corporate perspective, I could just hire someone with experience in Drupal, like Bryght. But I’m not building a big community site, and I’m not willing to pay someone to do it for me. I’m largely doing this for the fun of it, and Drupal doesn’t seem to be a lot of fun.

So I’m back looking again. MT has cleaned up their prices, so I could just install MT 3.1 and be done with it. It wouldn’t be a lot of work to upgrade, and there’d be a handful of benefits, but it still wouldn’t give me an HTML photo gallery or a decent interface for static non-blog pages.

I’m fighting off the urge to use Rails to write a blogging system for myself. Hopefully, if I fight off the urge long enough, then someone else will do it for me, and I can just take their framework and adapt it to my needs. One can always hope :-).

Posted by Scott Laird Wed, 01 Sep 2004 16:27:00 GMT