Hello, I'm Alan

Stripped down Rails

Tuesday, March 17 2015

Still seems like enough people don’t know, you can rip whole bits out of Rails, which is great when making an API app.

The rails-api gem is great, but if you depend on Rails, it drags in things you may have no use for in an API app, such as sprockets.

My Gemfile

source 'https://rubygems.org'

gem 'railties', '4.2.0'
gem 'actionpack', '4.2.0'
gem 'activemodel', '4.2.0'
gem 'activerecord', '4.2.0'
gem 'activesupport', '4.2.0'

gem 'pg'

gem 'active_model_serializers', '~> 0.8.3'
gem 'unicorn'
gem 'jwt'
gem 'rack-cors', require: 'rack/cors'
gem 'rails-api'

group :development, :test do
  gem 'rspec-rails'
end

Also, in config/applicaiton.rb you probably have a line require 'rails/all', but you can get away with less Rails than that. I only include the bits I need:

require 'active_model/railtie'
require 'active_record/railtie'
require 'action_controller/railtie'
require 'rails/test_unit/railtie'

I should point out that I need test_unit there even though I use rspec, as rspec depends on it

Gems included by the bundle:
  * actionpack (4.2.0)
  * actionview (4.2.0)
  * active_model_serializers (0.8.3)
  * activemodel (4.2.0)
  * activerecord (4.2.0)
  * activesupport (4.2.0)
  * arel (6.0.0)
  * builder (3.2.2)
  * bundler (1.8.5)
  * diff-lcs (1.2.5)
  * erubis (2.7.0)
  * i18n (0.7.0)
  * json (1.8.2)
  * jwt (1.4.1)
  * kgio (2.9.3)
  * loofah (2.0.1)
  * mini_portile (0.6.2)
  * minitest (5.5.1)
  * nokogiri (1.6.6.2)
  * pg (0.18.1)
  * rack (1.6.0)
  * rack-cors (0.3.1)
  * rack-test (0.6.3)
  * rails-api (0.4.0)
  * rails-deprecated_sanitizer (1.0.3)
  * rails-dom-testing (1.0.5)
  * rails-html-sanitizer (1.0.2)
  * railties (4.2.0)
  * raindrops (0.13.0)
  * rake (10.4.2)
  * rspec-core (3.2.2)
  * rspec-expectations (3.2.0)
  * rspec-mocks (3.2.1)
  * rspec-rails (3.2.1)
  * rspec-support (3.2.2)
  * thor (0.19.1)
  * thread_safe (0.3.5)
  * tzinfo (1.2.2)
  * unicorn (4.8.3)

I’m still trying to get rid of the dependency on nokogiri, but that’s a mission for another day.