プロジェクト

全般

プロフィール

Vote #74805

未完了

url_for causes routing problems if a plugin uses namespaces

Admin Redmine さんが約2年前に追加. 約2年前に更新.

ステータス:
New
優先度:
通常
担当者:
-
カテゴリ:
Plugin API_20
対象バージョン:
-
開始日:
2022/05/09
期日:
進捗率:

0%

予定工数:
category_id:
20
version_id:
0
issue_org_id:
15872
author_id:
44924
assigned_to_id:
0
comments:
10
status_id:
1
tracker_id:
1
plus1:
0
affected_version:
closed_on:
affected_version_id:
ステータス-->[New]

説明

Redmine currently uses a hash parameter as the url to pass to url_for in many places
for example - lib/redmine.rb (pusing items to menu)

I have a complex plugin which uses namespaces for controllers and models.
Since url_for keeps the current namespace it will create the wrong url.

You can read more about the problem here:

http://blog.enriquez.me/2010/2/21/namespaced-controller-and-link-to-helper-in-rails/

Please consider adding "/" to controller when using url_for or use restful paths.
Thanks.


journals

Would it work when Redmine is deployed on a subURI?
--------------------------------------------------------------------------------
I will test.
--------------------------------------------------------------------------------
eyal R wrote:
> Please consider adding "/" to controller when using url_for or use restful paths.
> Thanks.

A patch is welcome, thanks.
--------------------------------------------------------------------------------
Hi, folks,

I ran into this same issue, so here's a patch. All it does is add the necessary forward slashes in 6 spots. I can't guarantee that that I found every occurrence, but it's enough to get my plugin working, so may also be helpful for others. Doesn't seem to break anything (dangerous words, I know...).

The patch is against trunk/14622.
--------------------------------------------------------------------------------
Should add: I haven't tested this with Redmine installed on a sub-URI. Will do that... so wait a bit before applying the patch. :)
--------------------------------------------------------------------------------
Hi again,

Using Apache and Passenger, it does work while installed on a sub-URI, as far as I can tell. Also seems to work under WEBrick, if you tweak "config.ru":
<pre><code class="ruby">
require ::File.expand_path('../config/environment', __FILE__)
map '/redmine' do
run RedmineApp::Application
end
</code></pre>

Cheers...
--------------------------------------------------------------------------------
How about thin and puma?
--------------------------------------------------------------------------------
I don't know... give them a try and let us know!
--------------------------------------------------------------------------------
Another issue linked to namespaced controllers is Menu items that use hashed urls with the controller field like :
<pre><code class="ruby">
menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
</code></pre>

To fix that, you can patch MenuHelper like this :

<pre><code class="ruby">
module MyPlugin
module MenuHelperPatch
# Method overriden
def extract_node_details(node, project=nil)

item = node
url = case item.url
when Hash
url_hash = item.url.dup

# Specific : manage controllers in namespaces
if url_hash.has_key?(:controller) && !url_hash[:controller].starts_with?('/')
url_hash[:controller] = "/#{url_hash[:controller]}"
elsif url_hash.has_key?('controller') && !url_hash['controller'].starts_with?('/')
url_hash['controller'] = "/#{url_hash['controller']}"
end
# END -- Specific : manage controllers in namespaces

project.nil? ? url_hash : {item.param => project}.merge(url_hash)
when Symbol
if project
send(item.url, project)
else
send(item.url)
end
else
item.url
end
caption = item.caption(project)
return [caption, url, (current_menu_item == item.name)]
end
end
end

Redmine::MenuManager::MenuHelper.send(:prepend, MyPlugin::MenuHelperPatch)
</code></pre>

* Another issue is the layouts/base template
It has to be overriden for the search links (/search)
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------


related_issues

duplicates,Closed,22048,Exception throws during plugin rendering

Admin Redmine さんが約2年前に更新

  • カテゴリPlugin API_20 にセット

他の形式にエクスポート: Atom PDF

いいね!0
いいね!0