我有一個模型「東西」,其中每一個has_many「評論」,每一個has_many「投票」。我希望能夠投票評論關於事情顯示頁面。這是我到目前爲止有:Rails 4:'redirect_to current_thing'undefined error
評論控制器:
def votecomment
@comment = Comment.find(params[:id])
Vote.create!(voteable_id: params[:id], voteable_type: 'Comment')
redirect_to current_thing
end
事物的看法:
<%= link_to 「Vote」, vote_comment_path(:id => comment.id), method: :post %>
路線:
post 'comments/:id/vote' => 'comments#vote', as: 'vote_comment'
但我又回到這個錯誤:
NameError in CommentsController#votecomment
undefined local variable or method `current_thing' for #<CommentsController:0x007f98efa69c00>
我試着將方法移到東西控制器,但我得到了完全相同類型的錯誤。
我在做什麼錯?
嘗試'redirect_to @ comment.thing' – Santhosh 2014-11-14 12:22:52
你是怎麼想到'current_thing'的? – Santhosh 2014-11-14 12:24:29
你可以在你的控制器上發佈你的'current_thing'的代碼嗎? – 2014-11-14 12:26:01