2012-01-20 44 views
0

我正在使用thumbs_up gem提供用户在我的应用中对帖子投票。我希望用户上下投票,并遵循thumbs_up wiki中的指示开始工作。使用thumbs_up计算总票数

这里是后控制我的投票后续行动: -

def vote_up 
    begin 
     current_user.vote(@post,:true) 
     redirect_to [@topic.forum,@topic] 
     flash[:success] = "You have voted successfully" 
    rescue ActiveRecord::RecordInvalid 
     redirect_to [@topic.forum,@topic] 
     flash[:error] = "You have already voted for this one" 
    end 
end 

当我点击vote_up链接,我得到这个错误信息: -

cannot convert symbol into an integer

路线: -

resources :topics do 
    resources :posts do 
     member do 
     post :vote_post_up 
     post :vote_post_down 
     end 
    end 
    end 

查看: -

<li> <%=link_to "Vote Up", vote_post_up_topic_post_path(@topic,post), :method => :post%></li> 

这里有什么问题?

+0

你可以添加一些路线,这样我们就可以知道你的'vote_up'链接的样子:) – Rohit

+0

@Rohit我已经更新了问题 –

回答

0

从错误判断,并且该文档:https://github.com/brady8/thumbs_up

变化:

current_user.vote(@post, :true) 

到:

current_user.vote(@post, {:direction => :up}) 

“不能转换符号为整数” 是指,使用的是符号“:真”,它不被支持。

+0

感谢您查看它,但如果我改变它,我会得到另一个错误,未定义的方法'[]'为真:TrueClass –

+0

啊,对不起,试试:current_user.vote(@post,{:direction =>:up}) – spotman

+0

它给我的SQL错误: - Mysql2 :: Error:Column'voteable_id'不能是null:INSERT INTO'votes'('created_at','updated_at','vote','voteable_id','voteable_type','voter_id','voter_type')VALUES('2012-01-20 19:12: 08','2012-01-20 19:12:08',1,NULL,NULL,2,'User') –