Overriding named routes provided by Rails 3 Engines

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

    Routing rules defined in routes.rb are applied from the top down until a match is found. I was able to override the route defined in the mounted engine simply by moving the higher-priority rule above the line where the engine is mounted. So,

    get 'about', controller: 'static', action: 'about', as: 'about'
    mount My::Engine => '/'

    results in the app routing /about/ requests to (in this case) the static controller, whereas:

    mount My::Engine => '/'
    get 'about', controller: 'static', action: 'about', as: 'about'

    results in the app routing /about/ requests to the route defined in the mounted engine.

提交回复
热议问题