Last Updated: February 25, 2016
·
519
· gus

Capitalising namespaces in Rails

A common practice when building Rails API's is to namespace the logic under an Api directive, having a bit of an OCD problem I couldn't stand looking at a non-capitalised acronym.

Luckily for us (me?), we can use Rail's inflections to fix this little issue.

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'API'
end

Now I can look at my code without feeling anxiety!

class API::UsersController < ApplicationController; end