Alright so I have a plugin for Redmine (Rails Engines.) The plugin uses the hooks such that it’s HTML/controls get rendered on every page in Redmine.
I am receiving and sending information from this plugin to the controller. Now I have two options I can use in the javascript and css: relative pathing or absolute pathing.
Relative Pathing won’t work for every page since the URL paths may anywhere from one to three sections to path from (Since the control must work from every page). This option requires my plugin to be rendered at the same nested level in the URL every time which it is not.
Absolute Pathing works for a particular install, but my plugin breaks when others use it under installs where the path is not under the domain root i.e. http://www.mysite.com/redmine/ instead of http://www.mysite.com. This requires manual editing which is not elegant at all.
Is there any way to easily address this seemingly simple issue?
If it’s a CSS, JS, or image file you can use the tag helpers with the
:pluginoption (Rails engines patches these)Make sure that the plugin name matches it’s install directory (e.g. vendor/plugins/redmine_kanban in the example above).
To reference assets like images in your css, you can use an external css file and
url(../images/example.png. Rails Engines will copy the assets/ directory to public/plugin_assets/plugin_name/[images|javascripts|stylesheets] so you just need go down a directory to get to images.JavaScript is a bit more difficult. The best way would be to export a JavaScript variable of the current relative path. I do something like this to export the language translation strings to JSON to use in my JavaScript.
Hope this helps.