从 Rails 6 中的 bin/rails 路由中省略操作邮箱、activestorage 和导体路由? [英] Omit action mailbox, activestorage, and conductor routes from bin/rails routes in Rails 6?

查看:59
本文介绍了从 Rails 6 中的 bin/rails 路由中省略操作邮箱、activestorage 和导体路由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全新的 Rails 6 应用程序,config/routes.rb 中没有 任何东西bin/rails routes 的输出为 ActiveStorage、Action Mailbox 和 Conductor 提供了大量非常长的 url 列表.

I have a brand new Rails 6 app and without anything in the config/routes.rb, the output of bin/rails routes has a massive list of very long urls for ActiveStorage, Action Mailbox, and conductor.

这使得 bin/rails 路由 作为一种文档形式完全无用,尤其是因为 bin/rails 路由 的选项不允许过滤 事情.

This is making bin/rails routes completely useless as a form of documentation, especially since the options for bin/rails routes don't allow filtering out things.

我不想省略 Rails 的这些部分,因为我可能需要它们.但我更喜欢这些路线 a) 如果我不使用它们就不存在 b) 不显示在 bin/rails routes 中.

I don't want to omit these parts of Rails as I may need them. But I would prefer these routes a) not exist if I'm not using them and b) not show up in bin/rails routes.

有人知道怎么做吗?

推荐答案

从 Rails 6.0.2.1 开始,这是这样做的:

As of Rails 6.0.2.1, this is the way to do it:

config/application.rb 中,删除行 require "rails/all" 并替换为:

In config/application.rb, remove the line require "rails/all" and replace it with this:

# See https://github.com/rails/rails/blob/v6.0.2.1/railties/lib/rails/all.rb for the list
# of what is being included here
require "rails"

# This list is here as documentation only - it's not used
omitted = %w(
  active_storage/engine
  action_cable/engine
  action_mailbox/engine
  action_text/engine
)

# Only the frameworks in Rails that do not pollute our routes
%w(
  active_record/railtie
  action_controller/railtie
  action_view/railtie
  action_mailer/railtie
  active_job/railtie
  rails/test_unit/railtie
  sprockets/railtie
).each do |railtie|
  begin
    require railtie
  rescue LoadError
  end
end

请注意,如果您保留 actiontext,您仍然会包含一些活动的存储路由.不知道为什么.此配置基本上意味着您不能使用活动存储、操作文本或操作邮箱.将这些带回来会带回许多您永远不需要的路线.

Note that if you leave actiontext in, you still get a few active storage routes included. Not sure why. This configuration basically means you cannot use active storage, action text, or action mailbox. Bringing those back in will bring back many routes you will never need.

另请注意,此解决方案有成本,因为每次 Rails 版本升级时,您都必须检查 rails/all.rb 以确保没有添加您可能关心的新框架(或删除该框架)你不再需要了).

Also note this solution has a carrying cost because with each Rails version upgrade, you must examine rails/all.rb to make sure no new frameworks were added that you might care about (or removed that you no longer should be requiring).

这篇关于从 Rails 6 中的 bin/rails 路由中省略操作邮箱、activestorage 和导体路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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