Project

General

Profile

Actions

Defect #15872

open

url_for causes routing problems if a plugin uses namespaces

Added by eyal R about 10 years ago. Updated over 7 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Plugin API
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

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

redmine_patch_leading_fwd_slash.diff (2.69 KB) redmine_patch_leading_fwd_slash.diff patch for defect 15872 Gord Brown, 2015-09-25 18:57

Related issues

Has duplicate Redmine - Defect #22048: Exception throws during plugin renderingClosed

Actions
Actions #1

Updated by Etienne Massip about 10 years ago

  • Category set to Plugin API

Would it work when Redmine is deployed on a subURI?

Actions #2

Updated by eyal R about 10 years ago

I will test.

Actions #3

Updated by Jean-Philippe Lang about 10 years ago

eyal R wrote:

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

A patch is welcome, thanks.

Actions #4

Updated by Gord Brown over 8 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.

Actions #5

Updated by Gord Brown over 8 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. :)

Actions #6

Updated by Gord Brown over 8 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...

Actions #7

Updated by Toshi MARUYAMA over 8 years ago

How about thin and puma?

Actions #8

Updated by Gord Brown over 8 years ago

I don't know... give them a try and let us know!

Actions #9

Updated by Jérôme BATAILLE over 7 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)
Actions #10

Updated by Go MAEDA about 5 years ago

  • Has duplicate Defect #22048: Exception throws during plugin rendering added
Actions

Also available in: Atom PDF