Defect #11609
Override redmine routes.rb in a plugin in redmine 2.x
| Status: | Reopened | Start date: | ||
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | Jean-Baptiste Barth | % Done: | 0% | |
| Category: | Plugin API | |||
| Target version: | - | |||
| Affected version: | 2.3.0 | Resolution: |
Description
Currently, it doesn't seem possible to override redmine application routes in a plugin.
For instance, I want to override the home link to go to projects. I can hack redmine/config/routes.rb to have
root :to => 'projects#index', :as => 'home'and that works.
However, when I make a plugin and add this to routes.rb
RedmineApp::Application.routes.draw do root :to => 'projects#index', :as => 'home' endIt has no effect. I can see the route is added by seeing them in
rake routes however.
It seems this was possible in redmine 1.x (#3867)
Related issues
History
#1 Updated by Roger Mbiama Assogo 9 months ago
- File ChangeLog added
#2 Updated by Roger Mbiama Assogo 9 months ago
- File Makefile.apxs added
#3 Updated by Jean-Philippe Lang 9 months ago
- File deleted (
ChangeLog)
#4 Updated by Jean-Philippe Lang 9 months ago
- File deleted (
Makefile.apxs)
#5 Updated by Sergey Gnuskov 9 months ago
Same here, can't redefine root path in plugin to my controller on redmine 2.x. On 1.x it works.
#6 Updated by cam lafit 9 months ago
Hi
I confirm this problem, with redmine 2.x It's impossible to change route on plugi.
Actually, i find a solution via patch behaviour (http://www.redmine.org/projects/redmine/wiki/Plugin_Internals)
Not very simply
#7 Updated by Leo L 8 months ago
Bob Bottle wrote:
For instance, I want to override the home link to go to projects. I can hack
redmine/config/routes.rbto have
root :to => 'projects#index', :as => 'home'
and that works.
I did found that hack too, but if I hack routes.rb this way, when I try to access a project from the projects menu, I got an "500 internal server error".
Don't you ?
--
Leo.
#8 Updated by Leo L 8 months ago
Concerning my last comment, when I hack the routes.rb file the way Bob Bottle did, when I click on an evolution id/name or incident id/name, I got :
ActionController::RoutingError (No route matches {:controller=>"welcome"}):
app/views/issues/_edit.html.erb:34:in `block in app_views_issues_edit_html_erb___1214659690394619739_17271917100'
app/helpers/application_helper.rb:952:in `labelled_form_for'
app/views/issues/_edit.html.erb:1:in `_app_views_issues__edit_html_erb___1214659690394619739_17271917100'
app/views/issues/show.html.erb:129:in `_app_views_issues_show_html_erb__1382867738471145656_17340890220'
app/controllers/issues_controller.rb:118:in `block (2 levels) in show'
app/controllers/issues_controller.rb:115:in `show'
I don't understand why... Is there something I missed ?
--
Leo.
#9 Updated by Leo L 8 months ago
Leo L wrote:
Concerning my last comment, when I hack the routes.rb file the way Bob Bottle did, when I click on an evolution id/name or incident id/name, I got :
[...]
I don't understand why... Is there something I missed ?
Resolved.
Modifying the home page implies adding a new line below the root's home :
root :to => 'projects#index', :as => 'home' #add this new line : match '/', :to => 'welcome#index', :as => 'home'
--
Leo.
#11 Updated by Jean-Baptiste Barth 20 days ago
- Status changed from New to Closed
- Assignee set to Jean-Baptiste Barth
- Affected version changed from 2.0.3 to 2.3.0
- Resolution set to Fixed
Actually there's a prepend method in ActionDispatch::Routing::RouteSet (found it thanks to this stackoverflow question).
It doesn't work in a plugin's config/routes.rb because it is loaded after the initialization process, when first routes are already defined. But if you leave it in your init.rb file, it's evaluated soon enough, and it works. Example:
RedmineApp::Application.routes.prepend do root :to => 'my#page', :as => 'home' end
Maybe you'll have to also redefine welcome#index action so that url_for() calls in Redmine core work, but I don't know if this is necessary..
I close this issue as I think it answers the initial question, feel free to reopen if not.
#12 Updated by Ilya S 5 days ago
Jean-Baptiste Barth wrote:
Actually there's a
prependmethod inActionDispatch::Routing::RouteSet(found it thanks to this stackoverflow question).It doesn't work in a plugin's
config/routes.rbbecause it is loaded after the initialization process, when first routes are already defined. But if you leave it in yourinit.rbfile, it's evaluated soon enough, and it works. Example: [...]Maybe you'll have to also redefine
welcome#indexaction so thaturl_for()calls in Redmine core work, but I don't know if this is necessary..I close this issue as I think it answers the initial question, feel free to reopen if not.
i've tried solution you suggested, but it doesn't solve problem. Root path still leads to welcome controller. 'rake routes' says that's all fine - my custom route now on top, but problem still there. Any ideas?
#13 Updated by Toshi MARUYAMA 5 days ago
- Status changed from Closed to Reopened
#14 Updated by Jean-Baptiste Barth 5 days ago
No idea, it worked for me. As you imagine I wasn't sure it would work so I put this code in a plugin and rebooted my redmine instance, then it worked. Maybe it depends on the version of Rails, I tried with Redmine 2.3.1 (Rails 3.2.13), older versions of Redmine may behave differently.
#15 Updated by Ilya S 4 days ago
Jean-Baptiste Barth wrote:
No idea, it worked for me. As you imagine I wasn't sure it would work so I put this code in a plugin and rebooted my redmine instance, then it worked. Maybe it depends on the version of Rails, I tried with Redmine 2.3.1 (Rails 3.2.13), older versions of Redmine may behave differently.
it's really strange, i use same conf: ruby 1.9.3, redmine 2.3.1 stable, rails 3.2.13
#16 Updated by Jean-Baptiste Barth 4 days ago
- Resolution deleted (
Fixed)
Ok, I'll try to reproduce and see if I did everything correctly. Unfortunately I won't be at home until next tuesday, so I won't be able to run these tests before.