1

私はこの機能をプラグインとして見たことがなく、できればレールを使用してそれを実現する方法を考えていました。

私が求めている機能は、1 つのオブジェクト (映画) を、1 つのページ/フォームでプロット、エンターテイメント、独創性などのさまざまな属性によって評価する機能です。

誰でも助けることができますか?

4

3 に答える 3

1

それを行うためにプラグインは必要ないと思います...ARで次のことができます

class Film < ActiveRecord::Base
  has_many :ratings, :as => :rateable

  def rating_for(field)
    ratings.find_by_name(field).value
  end

  def rating_for=(field, value)
    rating = nil
    begin
      rating = ratigns.find_by_name(field)
      if rating.nil?
        rating = Rating.create!(:rateable => self, :name => field, :value => value)
      else
        rating.update_attributes!(:value => value)
      end
    rescue ActiveRecord::RecordInvalid
      self.errors.add_to_base(rating.errors.full_messages.join("\n"))
    end
  end

end

class Rating < ActiveRecord::Base
  # Has the following field:
  # column :rateable_id, Integer
  # column :name, String
  # column :value, Integer
  belongs_to :rateable, :polymorphic => true
  validates_inclusion_of :value, :in => (1..5)
  validates_uniqueness_of :name, :scope => :rateable_id

end

もちろん、このアプローチでは、評価名に複製がありますが、それほど悪くはありません(1つのフィールドに対してのみテーブルを正規化してもカットされません)。

于 2010-02-01T19:33:56.500 に答える
0

プラグインajaxfull-ratingを使用することもできます

于 2010-02-01T21:28:39.233 に答える
0

これは別の、おそらくより堅牢な評価プラグインです...しばらく前から存在し、Rails 2で動作するように改訂されました

http://agilewebdevelopment.com/plugins/acts_as_rateable

于 2010-02-03T03:39:49.497 に答える