I’m working on a new plugin that adds a new interface type to Foreman. So far things turn out OK. That new interface type can be selected and created through the host edit GUI. But after saving the new interface (successfully), the host overview fails to render due to the missing RABL template (in this case, api/v2/interfaces/types/dummy.json).
The stack trace points to the app/views/api/v2/interfaces/main.json.rabl template, which wants to render a specific RABL partial matching the interface type. I need to provide such a template accordingly, but how?
the plugin cannot match the (relative) path for this partial (especially since it is namespaced)
nor can I inject my own template among those of Foreman core
RABL templates can neither be substituted, monkey-patched or defaced (only extended), right?
I appreciate any hints or advice for this challenge.
I think I found my answer in the Katello Foreman plugin: Register an additional path to Rabl to look for templates. I’ll report back once I’ve gathered some experience with that…
Right on the money! With this snippet added to engine.rb, Foreman can display the new interface type on the overview:
initializer "foreman_dummy_interfaces.add_rabl_view_path" do
Rabl.configure do |config|
config.view_paths << ForemanDummyInterfaces::Engine.root.join('app', 'views')
end
end
Of course, the actual template file needs to be added, too.
Hope this will help plugin developers in the future. Possibly some Foreman dev will decide to add a hint about “add_rabl_view_path” to the How to Create a Plugin developer docs, too.
One more thing, to me it looks like every plugin needs to register its own Rabl templates directory with Foreman’s Rabl renderer! Otherwise, not even absolute paths to plugin partials will be found with extend_rabl_template: