UPDATE: I’ve written an updated article on this and the larger topic of organizing Javascript within a Rails project that includes Turbolinks.

The asset pipeline has made including javascript in Rails applications a breeze. Without any additional changes, the code included in your app is executed on every page. However, with a combination of CSS class scopes and a jQuery plugin, you can isolate certain javascript code to only run on specific pages.

The Problem

Imagine you have 2 pages in your application (landing and contact) and need an alert box to show up on the contact page only. How would you do it?

continue reading →

Facebook’s news feed popularized the relative timestamp format of “X hours ago”. For good reason too…why print an absolute timestamp so that people have to do the relative calculation in their head? It’s one less step for the user, and to be fair, pretty easy to implement.

Rails helpers to the rescue

Rails has a view helper aptly named time_ago_in_words. If you use the created_at attribute from a record, you could easily reference a relative timestamp from a corresponding view:

# app/views/posts/show.html.erb

Posted: <%= time_ago_in_words(post.created_at) %> ago

That’s great! But not enough…what happens when a user stays on the page for 10 min. and the latest post was no longer posted “1 minute ago”? Asking them to refresh the page every 10 minutes is no longer an acceptable answer.

continue reading →

2013

On Dec. 31, 2012, I sat around a dinner table with my wife and 4 of our friends. Discussing the upcoming New Year, we went around the table and shared our resolutions. My turn came and I said, “I’m going to finish an Ironman”.

Up until that point, my longest race of any kind was a half marathon - certainly no triathlons. So for me, this was biiiiiiig time. I honestly don’t know if anyone believed what I said that night. I’m not even sure I did. But nonetheless, I had said it out loud in the presence of friends. The same friends I’d later have to explain why I bailed - if I bailed.

continue reading →

It’s hard to write a Rails app without interfacing with an external service or API. In most cases, these services require a secret token or password. Since checking passwords in to source control is generally a bad practice, we need a good way to safely and reliably access these values in code.

I’ve tried a few gems that attempt to make this process easier and ultimately settled on a simpler solution - the combination of a few lines of code and ENV variables, which are accessible whether you manage your own infrastructure or use a PaaS service like Heroku.

continue reading →

I did an 8-day sprint to launch my Build a Ruby Gem email course and documented my progress through this series of blog posts.

Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Weekend Update Summary

Hope you had a great weekend!

Aside from hibernating inside due to the 6 extra inches of snow that wasn’t predicted, I spent some time with the course content this weekend. In efforts to do a final proofread, I noticed something wasn’t quite right. My goal for this course was to smooth over the conventions of a Ruby gem that go much less talked about. However, because I naively chose a gem that included Rails integration as the example, the content ended up being more about Rails than I had planned.

continue reading →

I did an 8-day sprint to launch my Build a Ruby Gem email course and documented my progress through this series of blog posts.

Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Weekend Update Summary

Happy Friday!

This morning I’m feeling well rested and finally on the home stretch. In the middle of the week, the remaining work felt overwhelming at times and I have a feeling that played in to me feeling exhausted.

Part of it was that each lesson has gotten substantially longer than I planned for. I think once I get in to the flow of writing, I tend to document everything for everyone. I don’t think everyone will need this level of detail, but I’d hate to leave it out, only to find that some users were left confused because of the lack thereof.

Here’s how the word count of each lesson shakes out so far:

continue reading →

I did an 8-day sprint to launch my Build a Ruby Gem email course and documented my progress through this series of blog posts.

Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Weekend Update Summary

I’m tired. Getting up around 5am all week has worn on me. Yesterday I felt like zombie…and it was mostly my own fault because I didn’t make it a priority to get bed a decent hour.

I’m not sure about you, but I function best with 7-8 hours of sleep. I generally can’t sleep longer than 8, and anything less than 7 is OK for a day or two, otherwise, it catches up with me. I think that’s what’s going on here…

continue reading →

I did an 8-day sprint to launch my Build a Ruby Gem email course and documented my progress through this series of blog posts.

Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Weekend Update Summary

I let myself sleep in until 5:30am this morning ;) I spent a few very unsuccessful hours wrestling with Wordpress last night and didn’t get to bed at the time I wanted. However, all is well. I was able to push out Day 4 of the Build a Ruby Gem Email Course without issue.

One of the things that I’m noticing about putting the course posts together is how much the content relies on outside resources. Whether it’s an external URL, the output of a command prompt, or a diff on Github…getting those together is a non-trivial amount of time.

continue reading →

I’m doing an 8-day sprint where I’m launching an email course on how to Build a Ruby Gem.

Day 1 | Day 2 | Day 3 | Day 4 | Day 5 | Day 6 | Weekend Update

Back at it

I hit the 5:00am goal this morning! It’s 6:15am and I’ve wrapped up the 2nd day of the Build a Ruby Gem Email Course.

Yesterday, I had some anxiety about the amount of writing involved in putting this course together. I’ve read a number of blog posts about building a Ruby gem, but most seem to assume you have a pretty in depth knowledge of creating gems, while others skip important details of the process. So I knew going in to it that I wanted to write about it a little differently. I wanted to talk more about theory of why things are being done vs. how the Ruby language works.

Thinking back to my first Ruby gem, I remember my frustration trying to understand the conventions of naming and file structure. So I’m writing the course I wish I had when I started.

continue reading →