January 2007
11 posts
1 tag
Unpopular Developer 2: Down With Big Testing
Have you ever written tests so big, so comprehensive, that every time you change something in your code, you have to change your tests accordingly? Have you ever spent more than 30 minutes writing functional tests for a controller, including individually submitting nils and invalid data to each action in turn? How about, have you ever had to use class_eval to awkwardly construct a set of...
Jan 25th
4 tags
Unpopular Developer 1: Come on in, The Water's...
Hi, I’m Floyd. This is my first post on Giant Robots, but I’m going to try and avoid a lot of fanfare and instead get right to the smashing. This is the first in a hopefully long-lived series of posts on unpopular development practices. That is, an analysis of how dogmatic application of so called ‘best practices’ are not always. Arguably this blog always has a long and glorious history in this...
Jan 23rd
Relax dont do it When you want to go to it
In apps I like to follow a pattern: each model has their own controller that handles the CRUD actions for that model. For example, the Blog model has the BlogsController and the User model has the UsersController. This is nice because if I need to know how to CRUD a particular model I know right where to look, in its corresponding controller. Ok let’s go with this some more. Say I have...
Jan 19th
Nulls. Can't live with 'em can't live without 'em
Let’s start with a simple example: class Company < ActiveRecord::Base has_many :users end class User < ActiveRecord::Base belongs_to :company end A Company has many users and a User belongs to a Company. A 1-to-many from Company to User. However, for this app a User may or may not belong to a Company. In other words a Company is optional for a given User. Let’s look...
Jan 18th
1 tag
Camping.goes :Camping
Many in the Rails community have at least heard of Camping, a “microframework” by why the lucky stiff. It was only recently that I discovered that it is genuinely useful, even inspiring, for small applications. I’m currently at work on a tiny application called Rubedo, which offers a tiny Icecast source client, with an also-tiny web frontend. I’m writing it in Ruby, and so I began to do the...
Jan 15th
5 tags
Squirrel - Once More, with Feeling!
I admit, the first iteration of Squirrel wasn’t really as super fabulous as I thought it would be. Because of how I was using the blocks, you couldn’t do a simple thing like access params. And since half the fun of it was being able to make good looking, flexible queries, not being able to use params was a giant pain. Now, however, I’ve managed to mix the clean, functional look of...
Jan 12th
Second refactoring of security roles
A little refresher on what not to do… The wrapper class approach is just fine for a single resource that needs security applied to it. For a refresher, here’s the model… class Article < ActiveRecord::Base # Columns include submitted and accepted end And here’s the wrapper that you would use in its place when in an Admin controller… class AdminArticle def...
Jan 12th
5 tags
Hiding Visor
An excellent little plugin, Visor is. You can have a Quake-style console that pops up whenever you want, in any app. Only trouble is that I wanted to be able to close Terminal.app and still have the Visor accessible. I found these directions linked off the Visor wiki to get rid of Terminal.app from the process list, which is a set in the right direction, but not perfect. There were some quirks...
Jan 12th
To each his own
Everyone loves blocks in ruby because you no longer have to write ‘for’ or ‘while’ loops. people.each do |each| puts each.name end That’s nice and short. And the collection is responsible for looping over its elements which makes sense because its their elements. So various Enumerable (the module that’s included in Array and Hash) methods expect a block and in return pass each of...
Jan 8th
5 tags
Keep your mongrels on a leash
We’re fans of Mac OS X over here, and a number of us have MacBooks or MacBook Pros on which we do our daily development work. And since we’re a Rails shop, we tend to keep around a few Mongrel processes on our local machines running hither and thither with our code. Normally, this would simply mean you keep Terminal.app open and have it running in there. However, I’ve taken to using Visor as...
Jan 2nd
5 tags
When to create?
The “find_or_create_by” feature in Rails’ ActiveRecord is pretty handy – sometimes you don’t know whether you have the record you want, but you’re sure you want to create one if you don’t have it yet. We’ve used this in places where the system has a concept of a “remote resource” with it’s own unique numeric key, and you want to use one line of code instead of 3 or 4 to express the “find or...
Jan 2nd