My Friend Bobby

Everyone has the same Bobby Mac story. Bobby led the weekend group rides out of Quad Cycles in Arlington. He was boisterous, self-deprecating, and always the center of attention. He'd start each ride reminding us to "be nice to everyone you meet" and "ride with love in your hearts and smiles on your faces." If you were new to the ride you'd be forgiven for thinking, "Is this guy for real?" It was his energy that made the whole thing work -- he brought together nervous newcomers in cargo shorts and weekend warriors riding bikes that cost more than your first car. Bobby made us all feel like part of the same tribe. Word spread through cycling circles a few weeks ago that Bobby was…

A Tour of jQuery UJS

We've all seen jquery-ujs peering at us from the Gemfile of our Rails app. What does that Gem do, exactly? I dedicated on Friday afternoon to figuring that out, and I wrote it all up for the thoughtbot blog. Join me on a tour of jQuery UJS.…

Better Tests Through Internationalization

Over on the thoughtbot blog, I explain the testing benefits of internationalizing your application from the get-go. The oft-cited reason for turning to i18n before there’s even a hint of needing to support additional languages is that it’s simply easier to do from the start. This is absolutely true but there are several other benefits to i18n that make it a worthwhile pursuit and something we suggest for all applications. Today we’re going to focus on the effect i18n has on your tests. There are also some good tips for getting started with i18n in Rails.…

The Perils of Uniqueness Validations

I detailed a common problem with Rails' uniqueness validation on the thoughtbot blog today. I consider it a best practice to keep your database appraised of most of the constraints you place on data at the application level, and in this case it turns out to be a necessity to do so.…

Taming Factory Girl List Creation

Tired of tests that were sneakily creating many more records than they needed to, I half-jokingly proposed that we monkey-patch Factory Girl to prevent the creation of lists bigger than two items. How many times do you really need more than two items from create_list anyway? The rationale and resulting Factory Girl monkey patch are explained on my post on the thoughtbot blog. Update : It wasn't such a crazy idea afterall. Josh added create_pair to Factory Girl for this purpose. Use it in place of create_list wherever possible. It also has the added beneift of having the same exact arguments as create.…

Seamlessly Navigate Vim and tmux Splits

Over on the thoughtbot blog I detailed my workflow for seamlessly switching between Vim and shell splits in tmux. I’m constantly stumbling over the disconnect between Vim and tmux splits. There’s a little mental hurdle I have to clear each time and I fail at that more often than I’d care to admit. It’s 2013; Shouldn’t the computer be able to figure out what I meant and just do that? As it turns out, yes. …

Re-enabling Password Pasting on Annoying Web Forms

As a 1password user, I usually have very long, unique, and random passwords for every site that requires one. I use the 1Password browser extensions to fill password forms for me, but on iOS I copy and paste the values manually. Some misguided web developers have decided pasting passwords should be prohibited and have added onpaste events to prevent it. The latest culprit I have encountered is Apple. While this is an infrequent annoyance it can be crippling. To combat it, I whipped up a bookmarklet that will run some JavaScript on the page to remove onpaste events from all password fields. To use the bookmarklet, drag the allow pwpaste bookmarklet link to your bookmark toolbar. When you encounter one of these annoying forms, simply…

Using rbenv with tmuxinator

Tmuxinator allows for easy configuration of tmux sessions. It's a handy gem, but hasn't received any major updates in quite some time. While it has support for specifying a project-level rvm version, it has not yet accepted either pull request that would add proper rbenv support. Not wanting to install a fork from GitHub, I found I could easily use the existing rvm support if I just shimmed calls to rvm into the equivalent call in rbenv. Tmuxinator will call rvm use and pass the version identifier set in the rvm key of the configuration file. All I had to do was translate this into the equivalent call to rbenv shell. I added the following function to my zsh configuration: function rvm () { if [[ $1 == 'use'…

Gemify Assets for Rails

The asset pipeline, introduced with Rails 3.1, makes it simple to include versioned external assets as application dependencies. Provided those assets are packaged as Ruby gems, the process is as simple as adding the gem to your Gemfile, running bundle install and, in the case of CSS and JavaScript, adding a require to the proper manifest file. Many popular CSS frameworks and JavaScript libraries are already available as gems. Search RubyGems to see if the assets you're interested in are already packaged this way. What if the JavaScript library you use isn't yet available as a gem? Packaging and publishing asset gems is simple. Here's your chance. External assets are made available in Rails via Rails engines. When the engine is loaded into your…

Simple Navigation in Rails

Most web applications call for at least one level of navigational structure. Many will have two or more levels and require the active node in each level to have distinct styling via an active class. I've seen as many navigation solutions as I've seen rails projects. Most look similar in that each level of navigation is represented by a partial. Some track the active node via local variables passed with the call to render, but this approach isn't very DRY. Some track the active node via instance variables on the controller, but this is a painful violation of MVC which gets especially tedious to maintain in multilevel scenarios. Thankfully, there's a mature, simple, and actively maintained solution just a gem away. Simple Navigation handles just…