Try using a sinatra filter to DRY up this code?