我有一个全新的 Rails 6 应用程序,但没有anything in the config/routes.rb
,输出bin/rails routes
有大量 ActiveStorage、Action Mailbox 和 Conductor 的超长 url 列表。
这是在制作bin/rails routes
作为一种文档形式完全没有用,特别是因为选项bin/rails routes
不允许过滤out things.
我不想省略 Rails 的这些部分,因为我可能需要它们。但我更喜欢这些路线a)如果我不使用它们则不存在并且b)不会出现在bin/rails routes
.
有谁知道如何进行这项工作?
从 Rails 6.0.2.1 开始,方法如下:
In config/application.rb
,删除该行require "rails/all"
并将其替换为:
# 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,您仍然会获得一些活动存储路由。不知道为什么。此配置基本上意味着您无法使用活动存储、操作文本或操作邮箱。将这些带回来将带回许多您永远不需要的路线。
另请注意,此解决方案具有一定的携带成本,因为每次 Rails 版本升级时,您都必须检查rails/all.rb
确保没有添加您可能关心的新框架(或删除您不再需要的新框架)。
Note:您还需要从以下文件中删除对活动存储的引用config/environments/*.rb
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)