Setting up a Rails 5 app from edge


Update: Many people reported issues with installing the proper version of Rack, so I’ve updated step 3 to account for that.

I just returned from RailsConf 2015 and wanted to checkout some of the new features of Rails 5 that @dhh highlighted in his keynote. Here’s how I got up and running on edge rails in a few quick steps.

1. Create the project directory

2. Setup your environment

Rails 5 requires Ruby >= 2.2.2. I’m using RVM in this case, but you can use whatever Ruby environment manager that works for you.

3. Install edge Rails so we can generate a new project

Note that we included both Arel and Rack from source as well. At the time of writing, ActiveRecord requires Arel >= 7.0.0.alpha which isn’t available on yet, and ActionPack requires Rack >= 2.0 which also isn’t released yet, so these two lines are required to resolve that dependency.

4. Generate the rails app

The --force flag will allow Rails to overwrite our Gemfile, and the --dev flag tells Rails to point to the edge version of Rails that we just bundled.

5. Profit!


Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts


Just about a year ago to date I posted some useful Bash shortcuts for Ruby on Rails commands. These are mix of aliases and functions that detect what version of Rails is present and routes commands which ever way that version expects, i.e. ./script/console versus rails console. Now that Rails 4.1 ships with Spring by default, there is yet one more way commands could be routed – through the spring binstubs. I’ve recently updated my shortcuts to account for this. Now my commands will use the binstubs if they are present, or fallback to the other version-dependent methods.

H/T to makandracards for helping me figure this out.

Cache busting AJAX requests and redirects

AJAX get and head requests are cached by default. This can cause problems when AJAX requests use the same URLs as a user would use during normal site navigation. jQuery can disable caching on a global or per-request basis. When doing so, jQuery adds a _={timestamp} parameter to the query string which should make each request unique. However, there are cases where an AJAX request results in a redirect which jQuery will happily follow. When that happens the _={timestamp} isn’t automatically appended to the new request, so the final response can still end up being cached by the browser even when you’ve told jQuery not to cache it. You can get around this in 2 ways:

  1. Make sure all redirects persist the _={timestamp} parameter, if present
  2. Add the proper header response parameters to prevent the browser from caching the request.

Here’s an easy way to implement the 2nd solution in Rails:

Dynamic enum fields in nested association forms in Rails Admin

We’ve had a few projects at Panoptic Development recently that made use of the RailsAdmin gem. Out of the box, RA satisfied about 95% of what we needed to do to complete each project, but there were a few edge requirements that we either had to make do without or find workarounds for. Don’t get me wrong, RA is a wonderful utility for quickly spinning up an administrative area for your Rails app. It’s loaded with really slick bells-and-whistles, and it has an incredibly flexible DSL for configuration. However, there are a few things it just doesn’t seem to be able to handle as-is and for which I’ve searched high and low for solutions for the last 9 months. I’m happy to report that I finally cracked one of these problems, and it wasn’t even all that complicated in the end.


Resources for addressing the Heartbleed zero-day OpenSSL bug

Heartbleed is a zero-day bug in many OpenSSL implementations, and effects a huge swatch of servers on the Internet. Here’s a list of resources I’ve been referencing:

I am thankful today for SaaS platforms and virtual hosting environments, as they’ve meant I’ve had to do a minimal amount of work on my end to patch the applications I maintain.

Happy 21st Birthday, Ruby!

Ruby wasn’t the first development language I fell in love with, and it probably won’t be the last, but it’s beautiful and fun and it’s my favorite tool in my toolbox at the moment. It turns 21 today. If you haven’t already, give it a try!

Some useful Bash shortcuts for Ruby on Rails commands

Read an updated article on my Rails shortcuts: Bash shortcuts to run Rails commands through Spring, Bundler, or ye olde scripts

Like any developer, I spend a lot of time in the terminal typing out commands. Anything I can do to cut down on keystrokes is a daily win, which is why I’ve got over 50 bash alias entries.

I frequently have to work on a several different Rails projects at a time, ranging in versions from 2.3 – 4.0. Hammering out commands for console, server or generate can get pretty tedious by the end of the day, so I came up with a couple shortcuts that I’m particularly fond of:

What I like most about the cons, srv and gen commands is that they eliminate the mental overhead of context switching when going from the old 1.x and 2.x projects where each command is a separate bin file versus the newer 3.x+ project where they are just arguments to the rails command – It’s the same alias for every project.

Using dig to view, backup and verify DNS zone records on OS X

I was recently asked by a client to consolidate all of their DNS zone records and domain name registrations from 2 separate services to a single provider. The FAQ page of the current DNS service recommended using the named-xfer shell command, but that utility isn’t available on OS X. I googled around and learned that dig is a suitable alternative.

Finding the nameservers

Dig can be used to find nameserver information for a given domain:

Viewing and Backing up DNS Records

Backing these up just requires you to send that output to a file: dig IN ANY >>

Once you’ve updated the nameservers for a domain you can verify if they’ve changed using the dig NS +short command.

Other useful dig commands

Integration Tests for a Custom PayPal Express Checkout Integration

Paypal Express Checkout is a great way to add or extend the checkout capabilities of an e-commerce store. Most e-commerce software bundles have support for this baked in, but when you’re working with a custom-built shopping cart and have to roll your own Express Checkout integration it can be a real bear. The PayPal developer documentation is fragmented and often contradictory, and it’s never entirely clear about what steps are required to setup a developer account. They also often refer to their services using different names. And their support system is slow and cumbersome.

Because of this, when I recently worked on an Express Checkout integration for a Panoptic Development client, it took us a lot longer than we expected. A lot of that additional time came from trying to workout a proper integration test suite that would exercise our custom integration points without actually needing to hit the PayPal servers with valid requests every time. It took a lot of trial and error, but in the end I was able to get these tests working by mocking some service calls and stubbing out methods from the PayPal SDK libraries we were using.

For anyone stuck in the same spot, I documented my efforts at StackOverflow: “How to configure integration test for PayPal Express Checkout using TestUnit in a Rails 2.3 app“. My current set of tests differ slightly from what is show there and I ended up refactoring quite a bit as I added new tests, but that question and answer should be a good starting point.


I’ve posted a gist of all of the moving parts of my current implementation of this:

Integration tests for PayPal Express Checkout using TestUnit in Rails 2.3


Configuring PhoneGap for cross-platform mobile development on Mac OS X Mavericks

One of my professional goals for this year is to publish a mobile app for at least one Panoptic Development client. I’ve been researching different cross-platform mobile development frameworks to see how they would fit various project leads, and a couple weeks ago I decided to give PhoneGap a try. It wasn’t as straight forward a process as their documentation would have one believe, so when I finally had it up and running I posted my own documentation on the Panoptic Blog.

Complete instructions at: Up and running with PhoneGap on Mac OSX

Go to Top
%d bloggers like this: