I'm trying to query for a specific vote within the vote_fu plugin so that I can destroy it. I need to do this as I've implemented the one vote per user policy, but I'd like user's to be able to remove votes.
So what I have is a Link model, which is voteable, and User as the voter. In theory, should I not be able to do something like:
@link.votes.find_by_user_id(current_user.id).destroy
Though votes is not a support method due to it not being a table I built in the db. I've read through vote_fu's documentation, and I can't really seem to find/or figure out how I'm supposed to destroying votes.
def destroy
@vote = Vote.find(params[:id])
@vote.destroy
respond_to do |format|
format.html { redirect_to(user_votes_url) }
format.xml { head :ok }
开发者_开发技巧 end
end
Is in vote_fu's lib, so I should be able to call a destroy on the vote, I just need to be able to find the vote.
Anyway, thanks for the help.
I was going about this the wrong way. My final code is as follows:
def unvote
@link = Link.find(params[:id])
@vote = current_user.votes.find_by_voteable_id(@link.id)
@vote.destroy
redirect_to :back
end
Then in my view:
<%= link_to "Delete Vote", unvote_topic_link_path(@topic, link), :method => :delete %>
and my route if you want the whole picture of everything going on:
resources :links do
member do
post 'vote'
delete 'unvote'
精彩评论