简体   繁体   English

Rails 3引擎:如何更改路由的优先级

[英]Rails 3 Engines: how to change the priority of your routes

I am working on extracting some of the functionality of one of my apps into an Engine. 我正在努力将我的一个应用程序的一些功能提取到引擎中。 It seems that the routes in your app are generated and then the routes for the engine. 似乎会生成应用中的路由,然后生成引擎的路由。 The end result is that my engine routes are considered low priority and my app routes are eating up all the requests before they ever get to the engine routes. 最终的结果是我的引擎路线被认为是低优先级,我的应用程序路线在它们到达引擎路线之前正在吃掉所有请求。 Is there way for me to control the priority of my engine routes? 我有办法控制发动机路线的优先级吗?

我通过将我的路径移动到我的引擎中的类方法并将它们加载到基本应用程序的路径文件的顶部来解决这个问题: 覆盖Rails 3引擎提供的命名路由

According to this discussion: http://groups.google.com/group/blacklight-development/browse_thread/thread/a22ee4636a70b485 根据此讨论: http//groups.google.com/group/blacklight-development/browse_thread/thread/a22ee4636a70b485

it used to be the other way around. 它曾经是另一种方式。

You might be able to figure out how to reverse it by digging into what changes they made when they fixed it. 您可以通过深入研究修复它们所做的更改来弄清楚如何逆转它。

Specifically this one has a hack that overrode plugin routes with app routes by loading the class inside of the Routing::RouteSet class http://robots.thoughtbot.com/post/159805560/tips-for-writing-your-own-rails-engine 特别是这个有一个hack,通过在Routing :: RouteSet类中加载类来覆盖带有app路由的插件路由http://robots.thoughtbot.com/post/159805560/tips-for-writing-your-own-rails -发动机

Obviously it's older rails - but I figured you might get some inspiration for your own needs :) 显然它是较旧的轨道 - 但我想你可能会得到一些灵感,以满足你自己的需求:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM