It seems that with Rails/AR and the Inflector
methods added to String
by ActiveSupport
, I would expect that by default,
Nested::ClassDerived::FromAR.name.tableize == Nested::ClassDerived::FromAR.table_name
But actually tableize
calls underscore
, and underscore
doesn't actually underscore the ::
nested class separator, instead replacing it with a /
to make a pathname. Perhaps this method should be called pathify
?
Anyway, I need actual underscores. So I'm thinking of defining a new String
inflector method:
def new_inflector
underscore.gsub('/', '_')
end
that would actually underscore the nested class name string.
So, my question is, what is the proper inflection of 'underscore
' in order to properly and conventionally name my new inflector method, without configuration. Would it be 'underscoreize
' (following the convention established by 'tableize
') or 'underscorize
'? Or perhaps underscoreify
?
Any insight appreciated.
Have you tried parameterize with an underscore as a separator?
parameterize('_')
This worked for me with Ruby 2.5.0 and Rails 5.1.6.
"Admin::Role".parameterize.underscore
#=> "admin_role"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With