1

We have a suite of applications that make heavy use of ActiveResource to provide data across the system. We also override model#as_json a lot to provide additional 'readonly' data for use by the client. This additional data is provided on every resource request and is creating performance issues, especially if we only want basic subset of the model data. Is it possible to request 'variants' of the return data (similar to how HTTP allows for basic info via HEAD requests, and whole response via GET requests)?

# Full response in JSON
def as_json(opts)
  super(opts).merge({
    "connected_person_name" => self.connected_person.name
  })
end

# A Partial response in JSON
def basic_as_json(opts)
  super(opts).slice("id", "name", …)
end

Ideally, I'd like to be able to have a controller respond_to { |f| … } style block choosing which JSON method to call based on some parameter of the request. I could include this an attribute, but as it's configuration for the request, and not a model attribute, this seems like the wrong place to put it. I feels like this should be part of the request header, but i haven't seen anything that covers my needs.

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
maniacalrobot
  • 2,413
  • 2
  • 18
  • 20

0 Answers0