Tech

Rails 2.3: default_scope

Posted in Tech on March 13th, 2009 by James – Comments Off

Rails 2.3 includes a new method called default_scope which provides an easy way to set default attributes on a model as it calls on records from the database.  After playing around with it a bit, I am certain that I’m going to avoid using this method for a few reasons.

Before I get to that, here’s the syntax:

You could set a default_scope for any number of conditions, but :o rder is really the only thing that makes sense to me (red flag number one) because nothing else would have fixed conditions for all database queries.

With this default_scope in place, we’re going to get an ORDER_BY ‘name’ ASC added to our SQL query when calling Person.all, Person.old, or Person.young. That’s all well and good until the query gets a little complex–what happens if we specify a different :o rder in the named scope or in the controller? As you might guess, the default_scope loses out to specifying a different :o rder in other methods.

Once your query gets complicated with includes and joins, you’ll find that suddenly the defaulted :o rder option does not show up in your query and all your people are completely out of order.  At that point, you’re back to square one needing to manually specify the order in a separate named_scope or in the controller logic.

The inconsistency here is intolerable, and the code also loses a lot of clarity when it is implemented since it will not work under all circumstances.  Personally, I like :o rder options visible in the controller (I put just about everything else in named_scopes) because the code stays clear.  Just seems to me that it’s better to leave this method out all together.

Safari 4 Beta

Posted in Tech on February 24th, 2009 by James – Comments Off

Apple has just released a public beta of Safari 4 for Mac and Windows.  Very impressive and incredibly snappy.  It has excellent developer tools built-in, improved tab management, and I love the Top Sites home screen.

For you Mac users out there, I can pretty much guarantee that you’ll find it faster and more friendly than FireFox, but give it a try for yourself.

Amazon S3 – worth every penny

Posted in Tech on February 23rd, 2009 by James – Comments Off

Over the past year or two I’ve constantly been moving my data around, typically because I switch between needing lots of disk space to needing specific data available from anywhere–plus it’s important that it’s all kept safe.  Amazon S3 provides both: unlimited pay-as-you-go storage and it’s accessible from any computer connected to the Internet.  I’ve started using it for everything.  Client work, personal backups, purchased music, and serving static content to the web.

Plus, it’s perfect for the web services that I’m continually developing.  I haven’t worked on a single project recently that doesn’t need file upload/storage in some capacity, so it just makes perfect sense to store all of this data on Amazon’s infrastructure.  I don’t have to deal with backups or bandwidth, I just set it and forget it.

As a developer, you’re really adding a substantial amount of work if you plan on setting up MogileFS, GFS, or HDFS or even NFS (yuck) to store data on your own server(s).  If you’re a startup we both know you have a lack of engineers available to manage it, and I guarantee you’ll sleep better at night with the certainty that your files and your clients’ files are safe and secure.  Plus the initial cost of setting up your own would be nothing short of outrageous.

Cost may seem like a caveat.  At $0.15/GB per month the cost can definitely become substantial, particularly if you’re just using it for personal storage (500GB = $75 / month).  But what’s it worth to know that all your family photos are stored and redundant?  Your music collection is ready for playback even if your house blows up (you never know). The files that your clients expect you to have on hand are deliverable within minutes over the Internet.

It’s not enough for me to have an external hard drive on my desk backing up my data.  My stuff is too important for that.  I’m guessing you think yours is too.

A few recommended ways to get your hands dirty with S3: try Transmit, Drop Box, or S3Fox.

ZList

Posted in Tech on February 23rd, 2009 by James – Comments Off

After giving Google Groups and a few other mailing lists a try, I decided to scratch the itch by writing my own.  The freely available mailing lists out there are so dated and unnecessarily complicated that it just made sense to reinvent a simpler wheel.  ZList is open source mailing list software driven by Rails 2.3.  You can view the source, fork and improve, or download and use ZList on GitHub.  ZList is currently under active development.

And coming up in the not too distant future: ZTicket - open source helpdesk software on Rails.