Vote #76014
完了link_to in Redmine::Hook::ViewListener omits url root
0%
説明
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' } # => Test # 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":https://gist.github.com/jgillich/97c88a99092c37e5d327 in the addon folder and type @fig 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.¶
journals
--------------------------------------------------------------------------------
Google "Redmine::Hook::ViewListener suburi".
http://goo.gl/A95cJa
On Windows bitnami.
<pre>
C:\Bitnami\redmine-2.6.0-1\apps\redmine\htdocs>bundle exec thin
-e production -a localhost -p 3000 --prefix /redmine start
</pre>
<pre><code class="diff">
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>'
</code></pre>
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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.
--------------------------------------------------------------------------------
This is fixed in r13960. Unfortunately, this fix works with Rails 4 only and won't be backported in 2.6 branch.
--------------------------------------------------------------------------------
Thanks! I guess I'll just use the workaround until then.
--------------------------------------------------------------------------------