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/