ruby-on-rails - 是否有适用于 Rails 3 的投票插件?

标签 ruby-on-rails

acts_as_voteable 和 vote_fu 在 rails 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

关于ruby-on-rails - 是否有适用于 Rails 3 的投票插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4190006/

相关文章:

ruby-on-rails - 带有自定义处理器和裁剪的 Rails 3.1 回形针错误

ruby-on-rails - Rails 3、Authlogic、NGINX 和 HTTP 基本身份验证不能很好地协同工作

javascript - Rails 从远程获取事件触发器 :true

ruby-on-rails - 如何使 Ruby 与 bash 兼容

ruby-on-rails - Ruby ArgumentError : unknown keyword, 但不知道为什么

ruby-on-rails - 如何强制yaml中的所有节点都是字符串

ruby-on-rails - Ruby on Rails:脚本/my_script与rake my_namespace:my_task

ruby-on-rails - 使用 ActiveSupport::JSON.decode 在 Ruby on Rails 中出现 JSON 解析错误

ruby-on-rails - Rails 3 : ActiveRecord observer: after_commit callback doesn't fire during tests, 但 after_save 确实触发

ruby-on-rails - rails : Edit record in Bootstrap modal