Overriding named routes provided by Rails 3 Engines

后端 未结 6 1624
一个人的身影
一个人的身影 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:34

    I'm afraid that there's no such easy way. The routes are defined in lib/action_dispatch/routing/mapper.rb:271, which calls add_route on the RouteSet (defined in rack-mount-0.6.14/lib/rack/mount/route_set.rb, and on line 71 the name is attached). There's no remove_route method, and the Engine's route is added last. You can add your route manually after the application is initialized with Rails.application.routes.draw instead of having it in routes.rb, or you can patch the Engine.

提交回复
热议问题