Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


ActiveSupport::Inflector.underscore messes up acronyms under namespaces #12510

wants to merge 1 commit into from

6 participants


For example:

ActiveSupport::Inflector.inflections do |inflect|
  inflect.acronym 'ISP'
  inflect.acronym 'ISPs'

  => "isps" (ok)
  => "some_isps" (ok)
  => "provider/is_ps" (should be provider/isps)

Has anyone had a chance to look at this yet? It is a simple and straight-forward fix.

Currently this issue breaks url_for in our application if we use namespaced model names with an acronym, among other problems. Ie, if the model was named Provider::ISP, the helper method would be incorrectly named provider_is_ps_url and url_for(Provider::ISP) fails with undefined method `provider_isps_url'


Please add tests and changelog entry


The patch already includes the test. I'll add a changelog entry.


Also please squash commits


@pftg does this look ok now?


Cc @fxn

@frodsan frodsan was assigned
@fxn fxn was assigned

Is anyone still looking at this? Given it's a bug, albeit small, it would be nice if it could be fixed (and possibly backported too, allowing us to remove a monkey-patch :wink:)


This is failing CI, can you update it and get it to pass?


The CI fail was on the master branch, if it is fixed I can rebase it.


I believe the regex in #14146 is slightly more elegant, closing in favor of that

@agios agios closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 26, 2013
  1. @agios
This page is out of date. Refresh to see the latest.
5 activesupport/
@@ -1,3 +1,8 @@
+* Fix the underscore inflection of acronyms directly after module names, as in
+ `"API::RESTful".underscore => "api/restful"`
+ *Alexandros Giouzenis*
* Fix `slice!` deleting the default value of the hash.
*Antonio Santos*
2  activesupport/lib/active_support/inflector/methods.rb
@@ -90,7 +90,7 @@ def camelize(term, uppercase_first_letter = true)
# 'SSLError'.underscore.camelize # => "SslError"
def underscore(camel_cased_word)
word = camel_cased_word.to_s.gsub('::', '/')
- word.gsub!(/(?:([A-Za-z\d])|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$1 && '_'}#{$2.downcase}" }
+ word.gsub!(/(?:([A-Za-z\d])|(\/)|^)(#{inflections.acronym_regex})(?=\b|[^a-z])/) { "#{$1}#{$2}#{$1 && '_'}#{$3.downcase}" }
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')!("-", "_")
1  activesupport/test/inflector_test.rb
@@ -118,6 +118,7 @@ def test_acronyms
["HTTP::Get", "http/get", "HTTP/get", "HTTP/Get"],
["SSLError", "ssl_error", "SSL error", "SSL Error"],
["RESTful", "restful", "RESTful", "RESTful"],
+ ["API::RESTful", "api/restful", "API/RESTful", "API/RESTful"],
["RESTfulController", "restful_controller", "RESTful controller", "RESTful Controller"],
["IHeartW3C", "i_heart_w3c", "I heart W3C", "I Heart W3C"],
["PhDRequired", "phd_required", "PhD required", "PhD Required"],
Something went wrong with that request. Please try again.