Is the correct Rails bend underscoreize underscore?

It looks like using the Rails / AR and methods Inflectoradded to Stringon ActiveSupport, I would expect that by default

Nested::ClassDerived::FromAR.name.tableize == Nested::ClassDerived::FromAR.table_name

But it actually tableizecalls underscore, but underscoredoesn't really emphasize, the ::nested class separator, instead replacing it /to create a path. Perhaps this method should be called pathify?

Anyway, I need actual underscores. So I’m thinking about defining a new inflector method String:

def new_inflector
  underscore.gsub('/', '_')
end

which would actually underline the name string of the nested class.

So, my question is: what is the correct inflection ' underscore' to correctly and conditionally call my new inflector method, without configuration. Will it be " underscoreize" (according to the agreement established by " tableize") or " underscorize"? Or maybe underscoreify?

Any insight was appreciated.

+5
source share
1 answer

Have you tried parameterizing with underscore as a separator?

parameterize('_')
+8
source

All Articles