I use RABL to output the Sunspot / SOLR result set, and the search result object consists of several types of models. Currently in the rabl view I have:
object false child @search.results => :results do attribute :id, :resource, :upccode attribute :display_description => :description code :start_date do |r| r.utc_start_date.to_i end code :end_date do |r| r.utc_end_date.to_i end end child @search => :stats do attribute :total end
The above works for one model; however, when several types of models are in the @ search.results collection, this fails because both classes do not have the same instance methods. Does anyone know how to have different type based attributes? Ultimately, it would be nice to conditionally expand another template in the result collection based on the type of object. Something like the pseudo code below:
child @search.results => :results do |r| if r.class == Product extends "product/base" else extends "some other class base" end end
source share