Archive for June, 2010


Breadcrumbs in Rails

I’ve been working a little with Ruby on Rails recently.  One of the things I needed was a good module for handling navigational breadcrumbs.  I googled around a bit, but wasn’t able to find anything that fit my needs.  The closest to what I wanted was this example on stackoverflow.  It was a great starting point, but I ran into issues when I wanted to use nested controllers.  I wanted something a little more flexible.  Here’s my final solution.  I’m still a complete noob at rails, so feel free to point out any improvements you may have.

Features:

  • Splits up the URL and looks up the controllers for each section
  • Assumes you have a ‘name’ field on your data structure
  • Doesn’t link the last item since it should be the current pag
  • Works with nested controllers
  • Converts underscores to spaces and titleize’s the labels
  • Easy to modify to fit your own purposes

Code:

def get_bread_crumb(url)
    begin
        breadcrumb = ''
        so_far = '/'
        elements = url.split('/')
        for i in 1...elements.size
       
            so_far += elements[i] + '/'
           
            if elements[i] =~ /^\d+$/
                begin
                    breadcrumb += link_to_if(i != elements.size - 1, eval("#{elements[i - 1].singularize.camelize}.find(#{elements[i]}).name").gsub("_"," ").to_s, so_far)
                rescue
                    breadcrumb += elements[i]
                end
            else
                breadcrumb += link_to_if(i != elements.size - 1,elements[i].gsub("_"," ").titleize, so_far)
            end
           
            breadcrumb += " » " if i != elements.size - 1
        end
        breadcrumb
    rescue
        'Not available'
    end
end

Usage:

<%= get_bread_crumb(request.request_uri) %>

Which converts a URL like this:

/admin/posts/12/comments/8

to breadcrumbs like this:

Admin » Posts » Breadcrumbs in Rails » Comments » Great Post!

 37 comments

Integrity

I remember a couple weeks after I graduated college going to the movies with some friends.  The girl behind the counter asked “student?”  We all said “yes”.  Of course, none of us were technically students anymore, but the girl behind the counter didn’t know that and she almost certainly didn’t care.  We all still had our students ID’s and we looked the same as when we were eligible for the student discount.  We joked about how many years it would be before we got called out on this little loophole.

But then my conscience started bothering me.  You see, one of the most important things in the world to me is that people trust me.  I want to be known as someone you can count on to do the right thing.  Someone who won’t screw you over.  Someone with integrity.

And in that moment it felt like I had sacrificed all of that to save a dollar.

So in one of my prouder moments, I turned around, walked back up to the counter and said to the surprised girl behind the desk “I’m not a student anymore. Sorry I lied.”

That was three years ago and since then I’ve had far bigger opportunities to stretch the truth for my own benefit.  In fact, the temptation to compromise my integrity is everywhere.  It would be so easy to tack on a couple extra hours when billing for some contract work.  It’s so easy to lie just to make myself look a little bit better than I am.  But integrity is doing the right thing, even if no one is watching.  Every time I’m tempted I think back on the feeling I had as I walked away into that movie.

And I wouldn’t trade that for the world.

 6 comments

Hey Josh, what are you doing now?

That’s the question I’ve been getting about 10 times a day lately.  It’s been 4 months since we shut down EventVue and my life has changed a lot since then.  I wanted to give a quick personal update to those of you who care about me and are interested.

After shutting down EventVue, Rob and I were immediately inundated with messages from friends and strangers alike.  I was blown away.  The outpouring of support was completely unexpected and I want to say “thanks” to everyone who reached out.  You reminded me once again how lucky I am to be a part of this community.

Next, I decided to take a month and travel around Australia and New Zealand.  The scenery was stunning and the trip gave me a much needed break.  It turns out startup life can be quite exhausting.  We’d been at it for 3 years and I was working 12 hours a day, 7 days a week right up to the end.  Going to the other side of the world gave me a much needed opportunity to clear my head.  It also reminded me that other things in life matter more than just working all the time.  I met a ton of great people and their nonchalant attitude towards their careers was pretty contagious.  I left for down under with the intention of figuring out my next startup or job, but over the month I was gone I felt every ounce of ambition drip out of me.  It was great.

After getting back to the States, I started wading through the dozens of job offers that had come in while I was gone.  I considered a few of them, but the month off left me with some serious commitment issues.  I knew I wasn’t ready to do another startup, but I could already feel that itch starting to come back.  The more I thought about it, the less it made sense for me to take another full time job.  I hated the idea of taking a full time job when there was still a high chance that I would just bail after a few months to do another startup .  As they say, you only get to leave Google once.

So instead, I said “yes” to some offers for consulting and contract work.  And that’s mostly what I’ve been doing.  It’s been a good chance to work on projects I find interesting with people I like.  It’s also given me a great opportunity to get my work-life balance straight once again.  I’ve been getting outside more and have started to get into rock climbing.  I’m loving it!  Summers in Boulder are amazing and I’m looking forward to lots of hiking and mountain biking this summer.

Another benefit of the contract work is that I have more time to play with ideas for my next startup.  I’ve realized that startups are an addiction and I’m thoroughly hooked.  One idea in particular has captured my attention.  It’s too early to say much, but the basic concept is that I want to change the way we grocery shop.  I’m trying to learn as much as I can about the grocery business and I’d appreciate any insight or introductions you can make along those lines.  I’m not planning to jump head-first into another startup quite yet, but it’s fun to start dreaming of new ideas again.

So, how’s life?  Better than I deserve.  I’m convinced we made the right decision to close EventVue — if for no other reason than I’m happier now than I’ve ever been.

 11 comments