Overriding named routes provided by Rails 3 Engines

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

    There is no way to override a route within an engine. Instead, you must define an overruling route. You can do this by calling prepend on the engine's router:

    An::Engine.routes.prepend do
      root :to => "somewhere#action"
    end
    

    If the engine's namespace is isolated, this will use the SomewhereController from inside the engine's namespace. If not, it will use the typical SomewhereController.

    If you want to override a route to return a 404, the best way I can think of is to redirect to a 404 page:

    match "/route_goes_here" => redirect("/404")
    

提交回复
热议问题