Last Updated: February 20, 2016
·
1.878K
· jcf

Teaching ActiveSupport proper capitalisation

If you use the autoloading part of Rails you might find yourself having to use incorrect class names, like FaqController, or Api::UsersController.

To get around this you can either stop using lazy-constant-lookup autoloading, explicitly require all your affected files, or teach ActiveSupport some new acronyms.

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym('API')
  inflect.acronym('APIs')
  inflect.acronym('FAQ')
  inflect.acronym('FAQs')
end

Don't forget to add the plural form, otherwise your acronym won't be recognised when converting from singular to plural, and viceversa.

For a list of what ActiveSupport knows about when it comes to inflecting your strings checkout https://github.com/rails/rails/blob/master/activesupport/lib/active_support/inflections.rb.