Photo-1 Photo-2 Photo-3 Photo-4 Photo-5 Photo-6



Full-time web developer. Part-time smart ass.

I'm Brent Collier.

After a year and a half as an engineer on Twitter's Trust & Safety team, I'm looking for my next gig. Contact me if you know of something interesting.


I decided to "role" my own... get it?

Posted on 07/26/2009

I had some spare time the other day, which doesn't happen often, so I thought I'd take advantage of it by building something useful rather than tenderizing my brain via social media like I usually do.

After hearing numerous complaints recently about shitty role/authorization implementations, I thought I'd take a stab at it, so I whipped up role_fu.  It's a rails plugin that simplifies the process of setting up role access rules for controller actions.

Check out the project page or the readme for more details.

If you've got any feedback, do me a favor and leave a comment on the project page, or just shoot me an email brentmc79(@)gmail(dot)com.


properly using the flash

Posted on 06/10/2009

Are those pants made of mirrors, because I can see myself in them...

No, I'm not going to tell you how to seduce the comic book superhero with an evening of dinner, cocktails, and smooth talk while demonstrating impeccable manners and etiquette.

What I am going to tell you is how to correctly use the handy Rails tool for passing objects between actions.  Now, this is no huge secret or stunningly clever trick.  In fact, you probably already know what I'm about to tell you.  It's just one of those things that I never think to do until after it's a problem.

In the typical Rails app, there a snippet/partial/whatever that displays anything from the flash hash with either :notice or :error keys.  If, in your controller action, you set flash[:notice] equal to some message and then redirect to another action, that message will persist through the redirect and get displayed on the subsequent view.

Here's the problem.  If, in your action, you just render a view template instead of redirecting, then the user will see that message like you intended but it will also still remain on the following request which may or may not be confusing.  Fortunately, there's an easy way to avoid this.

If you know you'll be redirecting, then there's nothing to worry about.  Business as usual.  But if you're not redirecting, just rendering a view, then you can use[:key].  The 'now' method only maintains the flash contents through the current request and is cleared before the next action.  Check it out.

def create
      @thing =[:thing])
        flash[:notice] = "Oh snap!  You created a thing!"
        redirect_to @thing
      else[:error] = "Damn dog, you messed up"
        render :action => :new

Notice how when the thing save without errors we use flash[] and redirect, but when there are errors we use[] and there's no redirect.  This will keep your app users from seeing any strance, out of place errors.

So that's it.  Like I said, it's nothing monumental.  As you were...


Git checkout woes [updated]

Posted on 05/06/2009

I ran into a strange issue while attempting to checkout a remote tracking branch of an Intridea project earlier today, so I thought I'd post up my work around.

I ran my normal checkout command, like so...

brent:~/Intridea/earthaid[master]$ git checkout -b prod origin/prod

which resulted in this error message

fatal: git checkout: updating paths is incompatible with switching branches.
Did you intend to checkout 'origin/prod' which can not be resolved as commit

After a bit of googling, I'm still not sure of the cause as most of the search results were related to issues around deploying tags, and I was merely attempting a checkout.  What I did find out was that I could specify the start point of my new branch by the revision/commit sha instead of the remote branch name, like so...

brent:~/Intridea/earthaid[master]$ git branch prod 02314583a99abdc276cde968c20babbadd23
brent:~/Intridea/earthaid[master]$ gc prod
Switched to branch "prod"

Once I had applied my changes, I just had to make sure to push them to the proper branch.



Ok, I'm a retard.  About a minute or two after I typed up this post, it occurred to me that Git couldn't resolve the remote branch name because I hadn't pulled first.  Yeah, that's right.  All I need to do was pull and then everything worked properly.