2012-01-20 42 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') –