nesquena/rabl — Issue #162: Add support for use in isolated Engines
Author: yeggeps
Created: 2012-02-08 22:41:32+00:00
State: open

There's a problem using Rabl::Builder.partial, and the methods that depend on it, when using Rabl in an isolated Engine
The problems lies in Rabl::Helpers.fetch_source and the root_path variable, since Rabl will be available to the parent app (Is there a way to prevent this?) it will read the Rails.root attribute from the parent app. The .rabl templates are isolated in the engine, so fetch_source will return nil.

The root_path in an isolated engine would be EngineName::Engine.root

```
def fetch_source(file, options={})
if defined? Rails
root_path = Rails.root
view_path = options[:view_path] || File.join(root_path, "app/views/")
file_path = Dir[File.join(view_path, file + ".{*.,}rabl")].first
elsif defined? Padrino
root_path = Padrino.root
# use Padrino's own template resolution mechanism
file_path, _ = @_scope.instance_eval { resolve_template(file) }
# Padrino chops the extension, stitch it back on
file_path = File.join(@_scope.settings.views, (file_path.to_s + ".rabl"))
end

if file_path
return File.read(file_path.to_s), file_path.to_s
else
nil
end
end
```

Any idea how I could solve this?

Thanks