This project is archived and is in readonly mode.
Scoped engines routing
Reported by teamon | August 3rd, 2010 @ 04:30 PM
Right now, there is no control over engine routes that are injected into base app. It is impossible to mount engine at "/foo/" instead of "/"
However it could be easily done with 9 lines of code.
# Some hacking
class Rails::Engine
def self.define_routes(&block)
@@__routes_block = block
end
def self.draw_routes(where)
where.instance_exec &@@__routes_block
end
end
# then
# my_app/config/routes.rb
MyApp::Application.routes.draw do |map|
scope "bar" do
MyEngine::Engine.draw_routes(self)
end
end
# my_engine.rb
require "rails"
module MyEngine
class Engine < Rails::Engine
define_routes do
match "/my_engine", :to => "my_engine#foo"
end
end
end
# $ rake routes
# bar_my_engine /bar/my_engine {:controller=>"my_engine", :action=>"foo"}
Comments and changes to this ticket
-
Andrew White August 20th, 2010 @ 10:41 AM
- State changed from new to wontfix
- Importance changed from to Low
I think that it's best to leave route customization to the engine itself. An engine may make assumptions about it's routes and if they're moved it may break the engine. If you feel this decision is incorrect please raise the issue on the rubyonrails-core mailing list.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>