Project

General

Profile

Plugins routes

Added by Jean-Baptiste Barth over 15 years ago

I start a new thread as I did not find any subject mentionning "map.from_plugin" with the search form.

I want to add my own routes in a plugin. Engines makes it possible by inserting a "map.from_plugin :myplugin" but as you might guess, I didn't want to modify Redmine core at first. So I had a look at the hook system and finally understood how to do (thanks to the unit test !).

Here is my implementation (please tell me if I do something wrong, but it works...)
- in config/routes.rb (already present)

    Redmine::Hook.call_hook :routes, :map => map
- in vendor/plugins/redmine_myplugin/init.rb (in the register block)
    class MyRoutes < Redmine::Hook::Listener
      def routes(context)
        context[:map].resources :mymodel
      end
    end
    Redmine::Hook.add_listener(MyRoutes)

In fact I'm just wondering why you didn't choose an implementation like this :
- in config/routes.rb

    Rails.plugins.each do |plugin|
      map.from_plugin plugin.name.to_sym
    end
- in vendor/plugins/redmine_myplugin/routes.rb
    resources :mymodel

It appears to me it's pretty more simpler, and a "rake routes" convinced me it produces the same routes... So I'd like to understand why you preferred do it your own way instead of using Engines' mechanism...

Thanks !


Replies (4)

RE: Plugins routes - Added by Eric Davis over 15 years ago

Jean-Baptiste Barth wrote:

It appears to me it's pretty more simpler, and a "rake routes" convinced me it produces the same routes... So I'd like to understand why you preferred do it your own way instead of using Engines' mechanism...

That might work. There were two cases I wanted to allow:

  1. plugin define it's own routes - which you show clearly above
  2. plugin overridding a Redmine route (e.g. Open ID plugin taking overriding the named route of map.signin 'login')

One is clearly shown above and it looks like Two would work with the following route:

# in vendor/plugins/redmine_myplugin/routes.rb
signin 'login', :controller => 'openid', :action => 'login'

Only problem is, rake routes isn't picking up the overridden route.

Would you mind opening a feature request for this and assigning it to me? Thank you for the improvement.

Eric

RE: Plugins routes - Added by Jean-Baptiste Barth over 15 years ago

Ok, thank you very much for all these infos (especially the "rake routes" behaviour that I didn't know at all). It seems override works also but I cannot be sure it will ever be the case in all circumstances.

I submit a ticket immediately, you'll be a better judge than me to see if it has to be changed or not.

RE: Plugins routes - Added by Eric Davis over 15 years ago

Thank you, your suggestion has been implemented. Good eye!

Eric

RE: Plugins routes - Added by Alexey Palazhchenko over 13 years ago

See this topic for actual information.

    (1-4/4)