【发布时间】:2014-09-18 22:05:32
【问题描述】:
我有一个关注点和两个包含它的类。在关注点中,我定义了一个变量。这是关注点和两个模型:
module UserInstance
extend ActiveSupport::Concern
included do
ACTIVE = 'active'
end
end
class Guardian < ActiveRecord::Base
include UserInstance
end
class Student < ActiveRecord::Base
include UserInstance
end
我收到以下警告:
/app/app/models/concerns/user_instance.rb:12: warning: already initialized constant UserInstance::ACTIVE
/app/app/models/concerns/user_instance.rb:12: warning: previous definition of ACTIVE was here
我猜一旦它加载了一个类(如Guardian),它也会加载常量,并且加载另一个类会尝试再次加载常量,然后给出警告。我怎样才能避免这种情况而不必将常量放在两个模型中?谢谢
【问题讨论】:
标签: ruby-on-rails-4