为SendGrid设置词形变化意味着我们可以为Rails的文件命名方案设置一个例外。我们可以将模型命名为SendGrid...,而不必将文件命名为send_grid_...。然而,它在这里引入了一个与依赖相关的问题。我使用的是sendgrid-actionmailer gem,它使用模块名称ActionMailbox::Ingresses::Sendgrid注册入口,但是前面的首字母缩写定义意味着查找需要SendGrid。
config/initializers/inflections.rb
# frozen_string_literal: true
ActiveSupport::Inflector.inflections(:en) do |inflect|
...
inflect.acronym 'SendGrid'
end在生产环境中运行时,我使用sendgrid-actionmailer:
/app/vendor/bundle/ruby/2.7.0/gems/actionmailbox-6.0.3.2/app/controllers/action_mailbox/ingresses/sendgrid/inbound_emails_controller.rb:47:in `<module:ActionMailbox>': uninitialized constant ActionMailbox::Ingresses::Sendgrid (NameError)
Did you mean? ActionMailbox::Ingresses::SendGrid
SendGridA maintainer suggests this problem relates more to ActiveSupport than sendgrid-actionmailer,我同意。他建议,临时解决这个问题的方法是删除缩写词声明,而使用Sendgrid。有没有更持久的解决方案,可以让我们把首字母缩写声明留在里面?
发布于 2020-08-27 20:56:14
在ActiveSupport::Inflections上定义词形变化会影响全局加载它们的方式。多亏了Rails docs,我发现你可以在Rails的加载器上重写变形。我最终需要将以下代码添加到初始化器(config/initializers下的.rb文件):
# frozen_string_literal: true
Rails.autoloaders.each do |autoloader|
autoloader.inflector.inflect(
'sendgrid' => 'Sendgrid'
)
end这将恢复加载器所知道的默认值。
https://stackoverflow.com/questions/63602277
复制相似问题