From 47f3bc94af22ba3e8c26ca51ce274e376da524f5 Mon Sep 17 00:00:00 2001 From: Alex Willemsma Date: Fri, 2 Oct 2015 12:09:01 -0700 Subject: [PATCH] Call model.model_name.name instead of model.class.name to determine responder path. ActiveModel supports a #model_name method which returns a class providing information about the model name, and removes the need to infer this from the class heirarchy. The default model_name can also be over-ridden, which is especially useful to have rails treat all sub-classes of an STI base model the same (using the base path) for view and other related file lookups. See also http://stackoverflow.com/questions/29527156/rails-sti-override-model-name-in-parent-class-for-all-subclasses --- lib/roar/rails/formats.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/roar/rails/formats.rb b/lib/roar/rails/formats.rb index bfd08a4..b8b3401 100644 --- a/lib/roar/rails/formats.rb +++ b/lib/roar/rails/formats.rb @@ -42,7 +42,7 @@ def collection_representer(format, model, controller_path) end def entity_representer(format, model, controller_path) - model_name = model.class.name.underscore + model_name = model.model_name.name.underscore if namespace = controller_path.namespace model_name = "#{namespace}/#{model_name}" @@ -71,4 +71,4 @@ def namespace end end end -end \ No newline at end of file +end