[英]Is there a voting plugin available for rails 3?
act_as_voteable和vote_fu在滑轨上不起作用。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
我正在使用Thumbs Up ,它的工作原理很吸引人。 这是对rails 3的vote_fu的改编。
Make_votable看起来像一个很棒且易于实现的gem。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.