The recent changeset to template lookup introducet the instance-based view_paths. The assumption has probably been that it
might be used by the developer for switching template roots at runtime, depending on context.
For instance, on an application servicing domain1, domain2 and domain3, each domain might have it's own template root.
That gets substituted in a pre_filter. The natural way to do this with view_paths would be to override the instance method and
inject the template directory into the result of super.
However, this is totally useless because for some weird reason view_paths gets called even before the controller recieves
a request. It also gets called before any of the user's filters take effect.
It has therefore become impossible to override the template roots per request. The use of a convoluted class attr assignment
for view_paths class attribute makes the situation even worse. Currently the only way I could circumvent this is by using
class MyController < ...
def view_paths
@tamperer ||= StringPromise.new(self)
super + [@tamperer]
end
end
class StringPromise
attr_accessor :controller
def initialize(ctr); @controller = ctr; end
def to_str
RAILS_ROOT + '/app/magazine-views/' + @controller.magazine.slug
end
def to_s; to_str; end
end
Which seems totally ass-backwards but works.
Can this breakage be resolved without refactoring the whole rendering pipeline? What has now become the recommended way
of doing template root substitution per request?