我正在尝试完成一个系统,我可以将用户放入名为“主持人”的组中,他们将获得带有文本主持人和组面板中指定颜色的引导徽章。
然后我可以说我把成员放在捐助者组中,他们也会获得徽章。我还计划让他们的用户名由最高优先级组(在组面板中设置优先级)着色,并且它将在后视图和主题视图中为它们提供该颜色。
我并不是要求实现这个,只是想弄清楚如何自己动手。
答案 0 :(得分:0)
class User < ActiveRecord::Base
has_and_belongs_to_many :groups # a user can be associated to a group that doesn't have a corresponding badge
has_many :badges # the association to a group through a badge is also possible but due to business constraints, this may not neccessarily be so
end
class Badge < ActiveRecord::Base
belongs_to :user
belongs_to :group
end
class Group < ActiveRecord::Base
has_and_belongs_to_many :users;
end