I am attempting to use the Exhibit pattern in a padrino application but to do so properly I need to access the rendering context. That is, I need to have some object context such that calling something along the lines of context.render('accounts/index') will produce identical output to when render 'accounts/index' is called from inside a controller (assuming that all variables are set the same and that app/views/accounts/index.erb is a template file).
I can’t find anything that does this within the padrino public API, so I attempted to dig deeper. The existing render method in the controller wraps sinatra’s render method, which is a private instance method. So it’s not obviously not defined on the class MyApp (i.e. the Padrino::Application subclass). MyApp.new results in an instance of Rack::Session::Cookie rather than of itself, and none of the padrino methods that I can find return the existing instance of the app, which would be a suitable candidate for the context object if I called its private render method.
Is this something that’s just inherently too difficult to bother with given sinatra’s and padrino’s designs, or is there something that I’m missing here?
I realise that the answer was in the Objects on Rails book if only I’d kept reading. I needed to pass the context explicitly from within the template:
exhibit(object, self)inside the template causes the template’s rendering context to be passed as the second argument. Of course.I guess this really wasn’t specific to padrino after all and I was looking for something complicated when the answer was very simple.