Multiple Plugins that Override Core Views
Added by Anonymous over 10 years ago
So, this morning I noticed that the Redmine Sidebar TOC plugin I installed is no longer displaying a table of contents for my wiki pages.. After a little bit of digging, it turns out I have more than one plugin overriding the app/views/wiki/_sidebar.html.erb
partial, in this case Redmine Tweaks.
I did manage to find a 2 year old thread with another user asking how these are handled internally, but there wasn't anything too helpful there. As far as I can tell, the plugins are loaded alphabetically, overriding with new view partials as they are found.
One workaround is to create a sort of "load me last" plugin that fixes things for my particular setup. I'm sceptical of the long-term effects here though; each time I update any of the plugins, I'll need to ensure my overrides are up to date and/or don't cause problems. ([ed] This idea doesn't seem to work as I intended, I can't seem to get my plugin to load last.)
Another workaround would be to manually modify each plugin that I use is order to prevent conflicts like this, but with my very limited understanding of Ruby, this sounds like a disaster waiting to happen.
Is there a better way to deal with this? Perhaps a way to import the "current state" of the template partial from a plugin's file (allowing me to append/prepend something to the view)? I'll copy/paste/hack a few code snippets into my override plugin idea in the mean time, but I'm really interested to see if there's a more graceful and permanent solution to this.
Replies (1)
RE: Multiple Plugins that Override Core Views
-
Added by Jean-Baptiste Barth over 10 years ago
There's no easy answer, but basically full views overriding is a single-shot idea, and there's no easy workaround. I think it should be discouraged when developing serious plugins. One solution would be to override rails' render
method to deal with that kind of cases but I think it's a very, very bad idea.
Maybe we could add a warning on boot to help redmine administrators detect when two plugins override the same view. What do you think ?
As of view modifications, the view hook mecanism is here for a long time and allows clean things, though it's a bit limited in the sense we cannot put view hooks everywhere around every single template line in redmine core (for obvious performance and maintenance reasons). I personnally heavily use deface to deal with that and I'm pretty happy with it.
If you have ideas about how we could deal with that I'd love to read them!