title: Subclasses and Rabl
body: <p>I have a feed that contains both parent and subclass objects, which i render using RABL into json. I include the root object in the json. </p>
  
  <p>The thing is this => depending on what comes first, the root node in the json will be generated with the corresponding class. </p>
  
  <p>I need it to be all of the parent class.</p>
  
  <p>Example below:</p>
  
  <pre><code>Class Klass
   ...
  
  Class SubclassOfKlass &lt; Klass
   ...
  
  k = Klass.create
  s = SubclassOfKlass.create
  
  array1 = [k,s]
  Rabl::Renderer.json(nil, 'answers/list', view_path: 'app/views', locals: {object: array1})
  
  ## results will render everything as "Klass" objects
  ## [{\"klass\":{\"_id\":\"1\"},{\"klass\":{\"_id\":\"2\"}]
  
  array2 = [s,k]
  Rabl::Renderer.json(nil, 'answers/list', view_path: 'app/views', locals: {object: array1})
  
  ## results will render everything as "SubclassOfKlass" objects
  ## [{\"subclass_of_klass\":{\"_id\":\"1\"},{\"subclass_of_klass\":{\"_id\":\"2\"}]
  
  ### But I need the root to be always "klass" and not "subclass_of_klass"
  </code></pre>
  
  <p>The rabl is as follows (pretty straightforward)</p>
  
  <pre><code># list.rabl
  collection @answers
  extends "answers/show"
  
  #show.rabl
  if @user
    node(:context_string) { |a| a[:context_string]}
    node(:notebook) do |a|
      if a.class == SubclassOfKlass
        a.notebook
      end
    end
  end
  
  extends "klasses/cache"
  </code></pre>