Skip to main content

Benjamin Oakes

Photo of Ben Oakes

Hi, I'm Ben Oakes and this is my geek blog. Currently, I'm a Ruby/JavaScript Developer at Liaison. Previously, I was a Developer at Continuity and Hedgeye, a Research Assistant in the Early Social Cognition Lab at Yale University and a student at the University of Iowa. I also organize, ICRuby, OpenHack Iowa City, and previously organized NewHaven.rb. I have an amazing wife named Danielle Oakes.

Filtering for the month August, 2013. Clear

Using dom_id with a presenter (or other objects)

by Ben

We have been using presenters much more often in our Rails code, with the goal of having views only use “Mustache-level” logic (conditionals, loops, and interpolation). We’ve been happy with the results so far; it really cleans up the views, and moves logic to easily testable objects. In fact, most tests for presenters can be fast specs and still test well.

I’ve gotten the impression that not everyone does presenters the same way, so before getting to the code I’ll clarify. Our presenters are decorator-like, with a restriction that they only transform values, not make any lasting changes to them. Methods are typically “opted-in” for use in the presenter using def_delegators from Forwardable. For a simple example, PersonPresenter might have a method called full_name that combines first_name and last_name; the Person class only manages the persistance of first_name and last_name. That is, presenters wrap an object with methods for presentation to a human.

Not all of Rails makes this pattern easy to use. We ran into an issue recently when calling dom_id() in a view. This was our code, roughly:

# File: app/presenters/foo_presenter.rb
class FooPresenter
  def initialize(foo)
    @foo = foo

  def bar
    # ...

  # ...

# File: app/controllers/foos_controller.rb
class FoosController < ApplicationController
  def show
    foo = Foo.find(params[:id])
    # It's nice to only have to expose a single object to the view.
    @foo_presenter =

  # ...
# File: app/views/foos/show.html.erb
<span id="<%= dom_id(@foo_presenter) %>"><%= %></span>

And this is the error we got:

ActionView::Template::Error (undefined method `to_key' for #<FooPresenter:0x007fc782994a98>):
1: <span id="<%= dom_id(foo_presenter) %>"><%= %></span>

The obvious fix would be to add a to_key method that just delegates to the model, but that quickly became a rabbit hole. Many more methods were needed, and I quickly gave up.

It turns out that dom_id() follows a protocol in that it will call to_model on whatever’s passed in. We can use that to solve our problem. (ActiveRecord objects just return self, as you might imagine.) Here’s the fix:

# File: app/presenters/foo_presenter.rb
def FooPresenter
  # ... (previous content)

  def to_model

Now the presenter can be used with dom_id(), delegating to the presented model. It’s a surprisingly simple solution. :)

(Versions: Ruby 2.0.0, Rails 3.2.12)

On moving across half the country

by Ben

Seven Things I Learned After Moving Across the Country.

Sell Everything – What I learned selling (almost) all of my belongings to start over and why you should too.

Our long distance move last year followed these posts pretty closely, although this was my first time reading them.  We had moved using a rented truck previously, and knew we didn’t want to spend that much again just to move non-essentials.

Although I can’t say it will be easy, I can recommend paring your belongings down before moving 1000 miles.  It’s funny how quickly new things can accumulate in the year after the move, though…  :)

Edit: To clarify, no we aren’t moving a long distance again. This was just some reflection on our move for others.  Sorry for any confusion!

Major unpatched OS X bugs

by Ben

Both bugs sound pretty serious.

Unpatched Mac bug gives attackers “super user” status by going back in time.

This vulnerability can allow an attacker root access to OS X.  Time related bugs like this sudo bug are really difficult to notice, but at least it’s fairly difficult to trigger.

Rendering bug crashes OS X, iOS apps with string of Arabic characters (Updated).

This bug, on the other hand, is likely to cause all sorts of issues as it becomes more well known.  Any application that uses Apple’s CoreText  will crash if it sees a certain string of Arabic characters.  There aren’t currently any security implications, and I admittedly thought of sending the text to Mac-using friends.  However, if your browser crashes every time you view a certain site or text message, this is why.  For some reason, this bug reminds me of the ping of death (e.g., in early versions of Windows).

Omaha’s PeggyBank archives MPegs and JPegs

by Ben

Startup Spaces: Sneak a peek at PeggyBank’s Omaha offices.

Clever name for the idea behind this archival startup. I had no idea this was going on in Omaha.


by Ben


A fast & lightweight polyfill for min/max-width CSS3 Media Queries (for IE 6-8, and more)

Seems like it would be useful for anyone that has to make their code work on IE8.

Self-hosted “Read It Later” App: Poche

by Ben

“Read Later” Apps Compared: Pocket vs. Instapaper vs. Readability.

I used to use Instapaper often, but was turned off by the price for mobile apps and (former?) incompatibility with Android.  Their web app isn’t very mobile friendly either.  Over time, I started using Instapaper less and less… Pocket seemed like a nice alternative, but I couldn’t really bring myself to switch.

Looking for a self-hosted alternative to other “read later” apps?  I’ve been pretty happy with Poche (PHP, demo) so far.  I even deleted my Instapaper account and switched to using Poche instead. It’s nice and lightweight, with a responsive design that works on phones, tablets, and desktops.

I haven’t gotten an offline version working (there’s an Android app though, and an export to ePub feature seems likely).  My only complaint so far? A lot of the user community only seems to discuss Poche in French (“poche” means “pocket” in French) — certainly something I’m not accustomed to in a largely Anglophone open source community.

Update: Poche linked back from their blog. Thanks!

CODE Mechanical Keyboard

by Ben

CODE Mechanical Keyboard via Coding Horror.

Looks pretty awesome, but I’d have a really hard time justifying spending $150 on a keyboard to myself. Highlights: backlit, good media keys, detachable micro USB cord (might work well with an Android tablet with USB OTG), and no Windows logo. :-)

The Onion on CNN

by Ben

Let Me Explain Why Miley Cyrus’ VMA Performance Was Our Top Story This Morning – The Onion.

That’s the Onion telling CNN how to be a respectable news organization. The Onion, the fake news site. What’s happened to journalism? If the only thing you care about is metrics like page views, you can easily be led astray. This really shouldn’t have been bigger news than Syria or the anniversary of the “I Have a Dream” speech. This isn’t the first time CNN has done something like this, either.

Flattr Tiny Tiny RSS

by Ben

Tiny Tiny RSS –

I’ve been a big fan of Tiny Tiny RSS since switching from the now defunct Google Reader.  (It’s still hard for me to believe Google discontinued it.)  I had a small Flattr balance from users of my open source software and readers of this blog, so I decided to pay it forward by flattring them.  I still love the Flattr concept, and hope it will continue to spread.


Hawaiian burger joint to open in Iowa City

by Ben

Hawaiian burger joint to open Aug. 18 in Iowa City | Corridor Business Journal

Teddy's Bigger Burgers

Seems pretty interesting; I’ve been curious about it when I walk by.  It’s interesting that Teddy’s Bigger Burgers is only in a few places:  Hawaii, Japan, Washington, and now Iowa.  I skimmed through their menu, and was happy to see they have vegetarian friendly fare alongside their kailua style and chili cheeseburgers.  Sounds worth a try.  :)