Following up on https://github.com/rails/rails/issues/15428, with adjustments.
Throughout the Rails code there are a few references to
object.class.model_name. Instead of always pushing this up to the class, it makes sense to me that we ask the model for its model_name.
This might obviate the need for the dubious ActionController::ModelNaming#model_name_from_record_or_class, https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/model_naming.rb
module ActionController module ModelNaming # Converts the given object to an ActiveModel compliant one. def convert_to_model(object) object.respond_to?(:to_model) ? object.to_model : object end def model_name_from_record_or_class(record_or_class) (record_or_class.is_a?(Class) ? record_or_class : convert_to_model(record_or_class).class).model_name end end end Example:
Foo.model_name == Foo.new.model_name