3

我在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
4

1 回答 1

3

可能发生此错误的原因有很多,但解决方法是不声明该常量。不确定您是否DistributionSlug::MATCH_REGEX在代码中的其他地方使用它,但如果不是,您可以执行以下操作:

class DistributionSlugConstraint
  def self.matches?(request)
    request.fullpath =~ /B[a-zA-Z1-9_]{5}/
  end
end

如果您在代码的其他地方使用它,您可以将其设为类方法并调用它而不是常量。另一种方法可能是将其声明为配置application.rb

我在使用多线程应用程序服务器(如puma,或在Sidekiq作业中)时看到过这种事情。在不了解您的基础架构的情况下很难说更多。

于 2018-12-24T18:40:49.863 回答