voxdolo/decent_exposure — pull request #92 by davidbiehl (2013-09-07 19:15:06+00:00)
Title: Fixes ancestor exposures on shallow routes (with eager loading)

In response to issue #89, this leverages the `belongs_to` association of a single model to eager load the "shallow ancestor"

#89 outlines the problem pretty well, this proposes the following changes to the exposure to enable smart shallow routes:

```ruby
expose(:patients, ancestor: :doctor, shallow: true)
```

First of all, for any member routes it will not use the `doctor` scope to find `patients`
Then it will eager load the doctor into the doctor exposure by (essentially) calling `Patient.find(params[:id]).doctor`. By doing this, the `doctor` exposure actually never gets called (there isn't a `doctor_id` on the request after all)

I first tried to override the exposure method itself (see 5d507e1) but this didn't work because the exposures live on the controller class, and therefore live between requests.

If you like this approach, I can use the same proxy object pattern to lazily eval the "shallow ancestor" like #91.