是否有针对rails 3的投票插件?

时间:2010-11-15 23:52:52

标签: ruby-on-rails

acts_as_voteable和vote_fu在rails 3上不起作用。有没有可行的?

4 个答案:

答案 0 :(得分:3)

它们设置起来非常简单。这是你可以开始的:

class Object < ActiveRecord::Base
   has_many    :votes, :as => :votable
   has_many    :voting_users,
               :through => :votes,
               :source => :user

#object_controller

  def vote_up
    get_vote
    @vote.value += 1 unless @vote.value == 1
    @vote.save
    respond_to do |format|
      format.html {render :action => 'view'}
      format.js { render :action => 'vote'}
    end
  end

  private

  def get_vote
    current_object = Objects.detect{|r| r.id == params[:id].to_i}
    @object = current_object
    @vote = current_object.votes.find_by_user_id(current_user.id)
    unless @vote
      @vote = Vote.create(:user_id => current_user.id, :value => 0)
      current_object.votes << @vote
    end
  end

答案 1 :(得分:2)

还有vote_fu和v ote_fu_rails3

答案 2 :(得分:1)

Make_votable看起来像一个很棒且容易实现的宝石。

答案 3 :(得分:1)

我正在使用Thumbs Up,它就像一个魅力。这是对ROails 3的vote_fu的改编。

相关问题