Overriding named routes provided by Rails 3 Engines

后端 未结 6 1623
一个人的身影
一个人的身影 2021-01-04 21:58

I am working on a Ruby on Rails 3(.0) application that uses a Rails engine. However, in my local application, I want to override one of the routes provided by the Rails engi

6条回答
  •  半阙折子戏
    2021-01-04 22:36

    You need add initializer hook to config/application.rb, like this:

    class Application < Rails::Application
    
      config.encoding = "utf-8"
    
      ...
    
      initializer :add_routing_paths do |app|
        their_routes_path = app.routes_reloader.paths.select{|path| path =~ /DIR/}.first
        app.routes_reloader.paths.delete(their_routes_path)
        app.routes_reloader.paths.unshift(their_routes_path)
      end
    end
    

    It's load roues.rb of you engine first and you can override their routes.

提交回复
热议问题