Defect #19024
closedlink_to in Redmine::Hook::ViewListener omits url root
0%
Description
Linking to a controller action omits the configured url root (RAILS_RELATIVE_URL_ROOT
environment variable).
For example, put the following code in a plugin & set RAILS_RELATIVE_URL_ROOT=/redmine
:
link_to "Test", { :controller => 'my', :action => 'plugin' } # => <a href="/my/plugin">Test</a> # Should be: href="/redmine/my/plugin"
There are quite a few others that seem to have the same problem:
https://github.com/peelman/my_projects/issues/5
https://stackoverflow.com/questions/25315103/link-to-omits-redmine-root
I am not sure if this is only reproducible under specific environments (at least the my_projects author doesn't seem to have this problem); I tried both the Bitnami Installer on Windows and the sameersbn/redmine
Docker container. You should get the same results with the following steps:
- Download https://github.com/peelman/my_projects
- On Windows: Install Redmine using Bitnami and put the plugin in the plugins folder
On Linux: Install Docker & fig, put this in the addon folder and typefig up
. - Open Redmine, create a project and go to the
Home
page. - Observe that all links generated by the plugin don't include the relative URL.
Updated by Toshi MARUYAMA almost 10 years ago
- Subject changed from link_to omits url root in plugins to link_to in Redmine::Hook::ViewListener omits url root in plugins on thin
- Category set to Plugin API
Updated by Toshi MARUYAMA almost 10 years ago
- Subject changed from link_to in Redmine::Hook::ViewListener omits url root in plugins on thin to link_to in Redmine::Hook::ViewListener omits url root in plugins
Google "Redmine::Hook::ViewListener suburi".
http://goo.gl/A95cJa
On Windows bitnami.
C:\Bitnami\redmine-2.6.0-1\apps\redmine\htdocs>bundle exec thin -e production -a localhost -p 3000 --prefix /redmine start
diff --git a/lib/my_projects/view_hook_listener.rb b/lib/my_projects/view_hook_listener.rb
index fc404d8..f099f08 100644
--- a/lib/my_projects/view_hook_listener.rb
+++ b/lib/my_projects/view_hook_listener.rb
@@ -42,10 +42,21 @@ class MyProjects < Redmine::Hook::ViewListener
return html
end
-
+
+ def suburi(url)
+ baseurl = Redmine::Utils.relative_url_root
+ if not url.match(/^#{baseurl}/)
+ url = baseurl + url
+ end
+ return url
+ end
+
def link_to_project(project)
html = '<li>'
- html += "#{link_to h(project.name), { :controller => 'projects', :action => 'show', :id => project } }"
+ # html += "#{link_to h(project.name), { :controller => 'projects', :action => 'show', :id => project } }"
+ url = suburi(url_for({ :controller => 'projects', :action => 'show', :id => project}))
+ html += "#{link_to(h(project.name), url)}"
+
html += " | #{link_to l(:label_issue_plural), { :controller => 'issues', :action=>'index', :project_id => project } } "
html += " | #{link_to l(:label_wiki), { :controller => 'wiki', :action=>'show', :project_id => project } } "
html += '</li>'
Updated by Toshi MARUYAMA almost 10 years ago
- Subject changed from link_to in Redmine::Hook::ViewListener omits url root in plugins to link_to in Redmine::Hook::ViewListener omits url root
Updated by Jakob Gillich almost 10 years ago
Are you saying that this has to be fixed in the plugins and not in Redmine? That seems wrong to me, the url root is something that Redmine supports by default, you can't possibly expect every single plugin to handle that case. Also, the core code uses just link_to
, I guess there is already some logic in place to prepend the url root.
Updated by Jean-Philippe Lang almost 10 years ago
- Status changed from New to Closed
- Assignee set to Jean-Philippe Lang
- Target version set to 3.0.0
- Resolution set to Fixed
This is fixed in r13960. Unfortunately, this fix works with Rails 4 only and won't be backported in 2.6 branch.
Updated by Jakob Gillich almost 10 years ago
Thanks! I guess I'll just use the workaround until then.