设计路由:有没有办法从Rails.application.routes中删除路由? [英] Devise routing: is there a way to remove a route from Rails.application.routes?

查看:107
本文介绍了设计路由:有没有办法从Rails.application.routes中删除路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

devise_for 创建通常的路由,包括DELETE路由。因为我们网站上有一个讨厌的错误(与IE 8不相关),我们只想完全删除DELETE路由。我们不需要它。

devise_for creates the usual routes, including a DELETE route. Because of a nasty bug on our site (related to IE 8 not behaving itself!), we just want to remove the DELETE route altogether. We have no need of it.

不幸的是, devise_for 不支持:除了:只有选项(从我可以告诉的)。

Unfortunately, devise_for doesn't support an :except or :only option (from what i can tell).

我想知道如何从Rails.application.routes中删除路由?

I'm wondering how i can remove a route from Rails.application.routes? Either in the draw block, or afterward?

谢谢!

编辑:上述错误的一些细节

EDIT: some details of the bug referred to above


  • 我们正在发行在控制器操作中删除对自定义UJS控制器操作

  • we were issuing a DELETE request to a custom UJS controller action

的请求,我们正在删除我们想要的,然后执行302重定向。这是一个坏主意,然后我们通过返回一些JSON来纠正它。

in the controller action we were removing what we wanted to, then doing a 302 redirect. This was a bad idea, and we have since corrected it by returning some JSON instead.

此错误已修复,但我想删除路线。

This bug has been fixed, but i would like to remove the route nonetheless.

编辑2 :所以我开始一个关于这个问题的赏金,我真的想知道它是否可能直接在RouteSet的Rails 。

EDIT 2: so i started a bounty on the question, i really want to know if its possible to party directly on the RouteSet in Rails.

编辑3 :这是我最后所做的,这是由Jose'Valim的报价中的赏金赢家建议的:

EDIT 3: Here is what i did in the end, which was suggested by the bounty-winner in his quote from Jose´ Valim:

config / routes.rb 中,我添加了上面的devise_for呼叫,设置了我的人民路线:

In config/routes.rb, i added this ABOVE the devise_for call which sets up the rest of my 'people' routes:

delete '/person', :to => 'people#destroy'

然后在我现有的 people_controller.rb 我添加了一个no-op方法:

Then in my existing people_controller.rb i added a no-op method:

def destroy
  render :nothing => true
end

这是在这种情况下可能工作的最简单的事情,它?我仍然有点感到,没有一种简单的方法来从RouteSet中删除路由。另外,设计控制器仍然存在 delete 路由,但是由于rails在 config / routes中找到第一个匹配项,所以它不会被调用。 rb 并返回。

This is the simplest thing that could possibly work in this situation, or is it? I'm still a little irked that there isn't a simple way to just remove the route from the RouteSet. Also, the delete route still exists for the devise controller, but it won't get called because rails looks for the first match in config/routes.rb and returns it.

好的,谢谢大家的帮助。

ok, thanks for the help everyone!

推荐答案

这是Jose Valim(设计者的作者)不得不说这个话题

Here is what Jose Valim (the author of devise) has to say on the subject:


没有办法单独删除路由。或者您使用:跳到
删除所有并绘制您需要手动或您覆盖这$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
route.rb


There is no way to remove routes individually. Or you use :skip to remove all and draw the ones you need manually or you overwrite this routes by defining a route to the same path first in your config/ routes.rb

所以你的问题的简短答案是否定的,你不能删除那条路线。您当然可以尝试像修补devise_for方法,但这将是一个有点牵涉的任务(一天或几天的努力)。我只是使用:skip选项,然后实现你想要的控制器的路由,而不是你没有的路由。

So the short answer to your question is no, you can't delete that one route. You can of course try doing things like patching the devise_for method, but that would be a somewhat involved undertaking (a day or several worth of effort). I'd just use the :skip option, then implement the routes you do want for that controller and leave off the one that you don't.

这篇关于设计路由:有没有办法从Rails.application.routes中删除路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆