代码之家  ›  专栏  ›  技术社区  ›  Kevin

每个型号多个等级的Rails插件?

  •  0
  • Kevin  · 技术社区  · 14 年前

    我想增加一个能力,评级一个模型,我有几个不同的类别,如“知识”“有组织”,等等。有一个插件可以让我这样做,甚至可能有一个酷的X/5星图形表示,以及?

    1 回复  |  直到 14 年前
        1
  •  0
  •   Daniel Beardsley    14 年前

    我不认为任何分级插件都支持这个,但是你可以制作一个名为 CatgoricalRating 设置如下:

    #This table has model_id, rating_category, and columns to support the rating system
    class CatgoricalRating < ActiveRecord::Base
      belongs_to :model
      acts_as_rateable  # (or any other rating plugin)
    end
    
    class Model < ActiveRecord::Base
      has_many :categorical_ratings
    end
    

    那么任何模型都可以通过这种关系获得任意数量的评级。

    你甚至可以把它变成 has_many :through 其中一个模型表示类别,“联接”模型将一个模型与一个类别关联,还包含评级信息。