Suppose we have a model CartItem, and somewhere in the code we have an instance of that model, @my_example_cart_item. What’s the cleanest way to use that instance and get to the String “cart_item”? I need the string to use as a scope in an I18N lookup. The following works, but seems awfully verbose:
@my_example_cart_item.class.model_name.underscore.downcase
# 'cart_item'
It is verbose, but it’s clear. If it’s something you’ll do often, create a method to express this more tersely.