我有这个呼叫我的投票模式:尝试使用CURRENT_USER它是未定义
fires :vote_updated, :on => :update,
:actor => :user,
:secondary_subject => :video,
:if => lambda { |vote| ((vote.value == 1) || (vote.value == -1)) && (vote.video.user != current_user)}
如果你不熟悉,它的工作原理与timeline_fu plugin。
如果拥有投票视频的用户是当前用户,我不希望该电话被解雇。这就是这条线进来:
:if => lambda { |vote| ((vote.value == 1) || (vote.value == -1)) && (vote.video.user != current_user)}
不过,我没有current_user
这里访问。我如何解决这个问题?
下面是我的票控制器创建方法(实际上有没有更新的方法):
def create
@video = Video.find(params[:video_id])
@vote = current_user.video_votes.find_or_create_by_video_id(@video.id)
if @vote.value.nil?
if params[:type] == "up"
@vote.value = 1
else
@vote.value = -1
end
elsif (params[:type] == "up" && @vote.value == 1) || (params[:type] == "down" && @vote.value == -1)
@vote.value = 0
elsif ((params[:type] == "up" && @vote.value == -1) || (params[:type] == "down" && @vote.value == 1)) || (@vote.value == 0)
if params[:type] == "up"
@vote.value = 1
else
@vote.value = -1
end
end
if @vote.save
respond_to do |format|
format.html { redirect_to @video }
format.js
end
else
respond_to do |format|
format.html
format.js
end
end
end
哪个控制器?这是什么样子? – 2011-04-18 05:14:12
哦,我明白你在做什么......我问的是不同的。这并不是说用户不能在自己的视频上投票,而是不管是谁投票视频,如果他/她是视频的所有者,则不会为current_user创建timeline_event对象。 – 2011-04-18 05:31:31
正确的,增加第二次更新 – 2011-04-18 06:30:13