我在config/routes.rb
中有以下课程。当我通过Elastic Beanstalk使用.ebextensions
文件部署应用程序时,该文件包括一个用于启动delayed_job
的部署后脚本,我收到:
...
warning: already initialized constant DistributionSlugConstraint::MATCH_REGEX
warning: previous definition of MATCH_REGEX was here
delayed_job: running [pid 14867]
...
config/routes.rb
中的类。
class DistributionSlugConstraint
MATCH_REGEX = /B[a-zA-Z1-9_]{5}/
def self.matches?(request)
request.fullpath =~ MATCH_REGEX
end
end
Rails.application.routes.draw do
constraints(DistributionSlugConstraint) do
get "/:slug" => "distributions#show", as: :distribution
end
end
答案 0 :(得分:2)
有许多原因可能导致此错误发生,但是一种解决方法是不声明该常量。不确定您在代码的其他位置使用DistributionSlug::MATCH_REGEX
,但是如果没有使用,可以执行以下操作:
class DistributionSlugConstraint
def self.matches?(request)
request.fullpath =~ /B[a-zA-Z1-9_]{5}/
end
end
如果在代码的其他地方使用它,则可以将其设为类方法,然后调用该方法而不是常量。另一条可行的方法是在application.rb
当使用puma
之类的多线程应用服务器或在Sidekiq
作业中时,我已经看到这种情况。在不了解您的基础架构的情况下很难说更多。