Cutting Rails’ Cable-ties

The first beta of Rails 5 has been released to the expected fanfare and excitement. Unfortunately, the inclusion of ActionCable in the default install introduces some rather annoying hard dependencies on Puma, Redis and EventMachine (amongst others).

Pull requests have been submitted, suggesting that perhaps ActionCable should be an optional requirement. DHH has made his position clear — ActionCable is part of Rails 5 and isn’t going anywhere—but they’re open to patches that help abstract / remove some of the more onerous core dependencies.

I’m keen to play around with the new features and updates to Rails, but at this stage I have zero interest in ActionCable, nor the effort required to get its dependencies installed. I’m also impatient. Give me the toys—NOW.

So, knowing what I know about Rails and its composition, I did some poking around to see if I could convince Rails to be not-so-omakase.

Skip Rails, install Railties

Here’s the not-so-dirty-secret: the Rails gem is simply a shell for the major components of Rails (ActiveRecord, et al). The gem that actually ties Rails together (and most importantly, contains the `rails` binary) is actually Railties.

> gem install bundler
> gem install railties --version 5.0.0.beta1

After installing its 20 dependencies, we should end up with…

> rails --version
Rails 5.0.0.beta1

So far, so good. Let’s try creating a new app and see what happens:

> rails new CableCutter --skip-action-cable --skip-bundle
> cd CableCutter
> head -n 15 config/application.rb
require File.expand_path(‘../boot’, __FILE__)
require “rails”
# Pick the frameworks you want:
require “active_model/railtie”
require “active_job/railtie”
require “active_record/railtie”
require “action_controller/railtie”
require “action_mailer/railtie”
require “action_view/railtie”
# require “action_cable/engine”
require “sprockets/railtie”
require “rails/test_unit/railtie”

Great—it’s not going to try loading ActionCable. But there’s still a problem:

> head Gemfile
source ''
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '>= 5.0.0.beta1', '< 5.1'

Damn. Still, that’s easily fixed—let’s just include the dependencies separately. Remove the reference to the Rails gem, and replace it with the following:

gem ‘activesupport’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘actionpack’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘actionview’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘activemodel’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘activerecord’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘actionmailer’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘activejob’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘railties’, ‘>= 5.0.0.beta1’, ‘< 5.1’
gem ‘sprockets-rails’, ‘>= 2.0.0’

While you’re there, you may as well remove the reference to Puma (unless you actually want to use it.)

That being done, let’s cross our fingers, run bundler and see what happens:

> bundle
Bundle complete! 19 Gemfile dependencies, 48 gems now installed.
> bin/rails server
=> Booting WEBrick
=> Rails 5.0.0.beta1 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server


One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.