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.
Written by James Conroy-Finn
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#