Defect #15872
openurl_for causes routing problems if a plugin uses namespaces
0%
Description
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.
Files
Related issues
Updated by Etienne Massip almost 11 years ago
- Category set to Plugin API
Would it work when Redmine is deployed on a subURI?
Updated by Jean-Philippe Lang almost 11 years ago
eyal R wrote:
Please consider adding "/" to controller when using url_for or use restful paths.
Thanks.
A patch is welcome, thanks.
Updated by Gord Brown about 9 years ago
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.
Updated by Gord Brown about 9 years ago
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. :)
Updated by Gord Brown about 9 years ago
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":
require ::File.expand_path('../config/environment', __FILE__)
map '/redmine' do
run RedmineApp::Application
end
Cheers...
Updated by Gord Brown about 9 years ago
I don't know... give them a try and let us know!
Updated by Jérôme BATAILLE about 8 years ago
Another issue linked to namespaced controllers is Menu items that use hashed urls with the controller field like :
menu.push :my_account, { :controller => 'my', :action => 'account' }, :if => Proc.new { User.current.logged? }
To fix that, you can patch MenuHelper like this :
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)
- Another issue is the layouts/base template
It has to be overriden for the search links (/search)
Updated by Go MAEDA almost 6 years ago
- Has duplicate Defect #22048: Exception throws during plugin rendering added