加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 删除Gem中指定的路由?

发布时间:2020-12-17 04:14:10 所属栏目:百科 来源:网络整理
导读:有没有办法删除Rails 3中的gem中指定的路由?异常记录器gem指定了我不想要的路由.我需要在路由上指定约束,如下所示: scope :constraints = {:subdomain = 'secure',:protocol = 'https'} do collection do post :query post :destroy_all get :feed endend
有没有办法删除Rails 3中的gem中指定的路由?异常记录器gem指定了我不想要的路由.我需要在路由上指定约束,如下所示:
scope :constraints => {:subdomain => 'secure',:protocol => 'https'} do 
    collection do
        post :query
        post :destroy_all
        get :feed
    end
end

基于Rails Engine docs,我想我可以创建一个猴子补丁并添加一个没有指定路径的路由文件[“config / routes”].paths数组但是文件没有被添加到ExceptionLogger :: Engine.paths [ “配置/路由”].路径

File: config/initializers/exception_logger_hacks.rb

ExceptionLogger::Engine.paths["config/routes"].paths.unshift(File.expand_path(File.join(File.dirname(__FILE__),"exception_logger_routes.rb")))

我离开基地吗?也许还有更好的方法吗?

解决方法

可以防止Rails加载特定gem的路由,这样就不会添加任何gem路由,因此您必须手动添加所需的路径:

在application.rb中添加一个初始化器,如下所示:

class Application < Rails::Application
...
initializer "myinitializer",:after => "add_routing_paths" do |app|
  app.routes_reloader.paths.delete_if{ |path| path.include?("NAME_OF_GEM_GOES_HERE") }
end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读