我担心存储常量的位置:
module Group::Constants
extend ActiveSupport::Concern
MEMBERSHIP_STATUSES = %w(accepted invited requested
rejected_by_group rejected_group)
end
我希望使用这些常量的另一个问题是:
module User::Groupable
extend ActiveSupport::Concern
include Group::Constants
MEMBERSHIP_STATUSES.each do |status_name|
define_method "#{status_name}_groups" do
groups.where(:user_memberships => {:status => status_name})
end
end
end
不幸的是,这会导致路由错误:
uninitialized constant User::Groupable::MEMBERSHIP_STATUSES
看起来第一个问题在第二个问题中没有正确加载。如果是这样,我该怎么办?