0

我正在尝试完成一个系统,我可以将用户放入名为“主持人”的组中,他们将获得一个带有文本主持人和组面板中指定颜色的引导徽章。

然后假设我将成员放在一个捐赠者组中,他们也会获得徽章。我还计划让他们的用户名由最高优先级组(在组面板中设置的优先级)着色,这将在帖子视图和主题视图中为他们提供该颜色。

我并不是要求实现这一点,只是想自己弄清楚如何去做。

4

1 回答 1

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

于 2013-06-13T19:09:50.067 回答