Feature #2142
Change the way plugin routes are integrated
Status: | Closed | Start date: | 2008-11-07 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | % Done: | 100% | ||
Category: | Plugin API | |||
Target version: | 0.8 | |||
Resolution: | Fixed |
Description
Plugin's routes can today ( r1977 ) be handled thanks to a hook in the config/routes.rb :
Redmine::Hook.call_hook :routes, :map => mapThe developper has to define his routes in vendor/plugins/redmine_myplugin/init.rb (in the register block) :
class MyRoutes < Redmine::Hook::Listener def routes(context) context[:map].resources :mymodel context[:map].connect 'mypath/:blah', :controller => 'mycontroller' #etc. end end Redmine::Hook.add_listener(MyRoutes)
Maybe it is possible to use Engines system to handle each plugin's routes, with "map.from_plugin" method :
- 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 connect 'mypath/:blah', :controller => 'mycontroller'
It has been discussed here in the forum. Maybe it would be easier to use for plugin developpers, but I'm not 100% sure routes overriding will produce the same effect.
Associated revisions
Removing the custom Redmine hook in routes in favor of Engine's hook.
- Plugins' routes.rb are now added automatically to Redmine's routing,
including the ability to override Redmine's default routing.Thank you to Jean-Baptiste Barth for the suggestion. #2142
History
#1
Updated by Eric Davis over 14 years ago
- Status changed from New to Closed
- Target version set to 0.8
- % Done changed from 0 to 100
- Resolution set to Fixed
I really like your suggestion and changed the way plugin routing works in r1991. Plugins' routes.rb
are now added automatically to Redmine's routing, including the ability to override Redmine's default routing.
Here's an example I put in a plugin to override the home page with the project list.
# vendor/plugins/redmine_test_plugin/routes.rb
map.home '', :controller => 'projects', :action => 'index'
#2
Updated by Eric Davis over 14 years ago
FYI: for documentation, the map
object in my example isn't required, this will also work
# vendor/plugins/redmine_test_plugin/routes.rb
home '', :controller => 'projects', :action => 'index'
#3
Updated by Jean-Baptiste Barth about 13 years ago
Just a quick note here since I may not be the only one to miss that : this way to configure routes in plugins has changed with r2887. You should have a look at this thread where Eric explains how to update your plugins.