ruby on rails - Subclasses and Rabl -


i have feed contains both parent , subclass objects, render using rabl json. include root object in json.

the thing => depending on comes first, root node in json generated corresponding class.

i need of parent class.

example below:

class klass  ...  class subclassofklass < klass  ...  k = klass.create s = subclassofklass.create  array1 = [k,s] rabl::renderer.json(nil, 'answers/list', view_path: 'app/views', locals: {object: array1})  ## results render "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 render "subclassofklass" objects ## [{\"subclass_of_klass\":{\"_id\":\"1\"},{\"subclass_of_klass\":{\"_id\":\"2\"}]  ### need root "klass" , not "subclass_of_klass" 

the rabl follows (pretty straightforward)

# list.rabl collection @answers extends "answers/show"  #show.rabl if @user   node(:context_string) { |a| a[:context_string]}   node(:notebook) |a|     if a.class == subclassofklass       a.notebook     end   end end  extends "klasses/cache" 

ok, answer turns out rather straightforward:

collection @answers, :object_root => "answer" 

Comments