我用這種寶石的評論:https://github.com/lml/commontator渲染用戶計票
這是建立方便地插入這塊寶石對評論進行投票:https://github.com/ryanto/acts_as_votable
一切似乎是工作的罰款。
:但是,試圖來計算用戶的總票數時(因緣)<%= @user.votes.count %>
我得到這個錯誤
undefined method `votes' for #<User:0x0000010dbf23a0>
所以,我想這(對用戶的所有意見收到的總票數)
<%= @user.comments.map{|c| c.votes.count}.inject(:+) %>
這導致另一個錯誤:
SQLite3::SQLException: no such column: commontator_comments.commontator_id: SELECT "commontator_comments".* FROM "commontator_comments" WHERE "commontator_comments"."commontator_id" = ? AND "commontator_comments"."commontator_type" = ?
如何呈現特定用戶在所有評論中收到的總票數?
安裝
commentator
和acts_as_votable
寶石後以下你試過'@ user.find_voted_items.count'還是'@ user.get_voted(Comment).count'? – usha
是的,都給了我一個NoMethodError –
你添加'acts_as_voter'用戶模型? – usha