How to override Rails app routes from an engine?

孤街醉人 提交于 2019-12-04 08:30:01

You could stick your engine routes in a method and then call that in your host app.

# engine routes.rb
module ActionDispatch::Routing
  class Mapper
    def engine_routes
      engine_envs GET    /engine/envs/:id(.:format)
      # ...
    end 
# ...

and then in your host app add the method before the catch-all route

# host app routes.rb
MyTestApp::Application.routes.draw do
  # ... 

  engine_routes

  match '/' => 'admin/rendering#show'
  match '*path/edit' => 'admin/rendering#show', :defaults => { :editing => true }
  match '*path' => 'admin/rendering#show'
end

Routes are used in the order they are defined. The first routes to be read are the one of the host application, then of your engine.

As soon as a matching route is found, the search for a route is stopped.

As far as I know, there are no way (I may be wrong about this) to override this feature other than to change your "mag

UPDATE: So that means that the order you see them in "rake routes" is the order they are processed. As soon as a matching route is found, there you go.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!