Defect #11609
closedOverride redmine routes.rb in a plugin in redmine 2.x
Added by Bob Bottle over 12 years ago. Updated over 9 years ago.
0%
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
Updated by Sergey Gnuskov over 12 years ago
Same here, can't redefine root path in plugin to my controller on redmine 2.x. On 1.x it works.
Updated by cam lafit about 12 years 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
Updated by Leo L. about 12 years ago
Bob Bottle wrote:
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.
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.
Updated by Leo L. about 12 years 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.
Updated by Leo L. about 12 years 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.
Updated by Ilya S over 11 years ago
Have same problem. Redmine 2.2.3.dev and 2.1.6 stable. This hack
root :to => 'projects#index', :as => 'home'
#add this new line :
match '/', :to => 'welcome#index', :as => 'home'
doesn't works too. How i can fix it?
Updated by Jean-Baptiste Barth over 11 years ago
- Status changed from New to Closed
- Assignee set to Jean-Baptiste Barth
- Affected version (unused) changed from 2.0.3 to 2.3.0
- Resolution set to Fixed
- Affected version changed from 2.0.3 to 2.3.0
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.
Updated by Ilya S over 11 years ago
Jean-Baptiste Barth wrote:
Actually there's a
prepend
method inActionDispatch::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 yourinit.rb
file, it's evaluated soon enough, and it works. Example: [...]Maybe you'll have to also redefine
welcome#index
action 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?
Updated by Toshi MARUYAMA over 11 years ago
- Status changed from Closed to Reopened
Updated by Jean-Baptiste Barth over 11 years 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.
Updated by Ilya S over 11 years 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
Updated by Jean-Baptiste Barth over 11 years 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.
Updated by Logan Raarup over 11 years ago
I found that this is fixed by changing the following in routes.rb
:
From:
Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir| file = File.join(plugin_dir, "config/routes.rb")
To:
Dir.glob File.join(File.expand_path("plugins", Rails.root), "*") do |plugin_dir| file = File.join(plugin_dir, "config", "routes.rb")
Updated by Jean-Baptiste Barth over 10 years ago
- Status changed from Reopened to Needs feedback
Logan Mazzoleni: could you please give us informations about your OS and ruby version ? I didn't manage to reproduce it (same as #12590), but your change would be ok I think if the problem still occurs on Redmine 2.5.2 with a supported ruby version. If not I guess it's better not to change anything. Sorry for the delay since last update :/
Updated by Jan Niggemann (redmine.org team member) over 9 years ago
- Status changed from Needs feedback to Closed
- Resolution set to No feedback