我有一個稱爲posts的表。其中我有一個名爲vote的列,它是一個整數。使用按鈕遞增數據庫
在我posts_controller我:
def upvote
@post = Post.find params[:id]
@post.votes = @post.votes +1
end
在我看來,我有
<%= link_to 'like', upvote(post.id)%>
而在我的路線我有
resources :posts do
member do
put :upvote
end
end
每當用戶點擊像我想它升高+1。我不斷收到一個錯誤:
undefined method `upvote' for #<#:0x007fc180f8d650>
它強調此行
<%= link_to 'like', upvote(post.id)%>
感謝您的幫助!
運行'''rake routes'''命令,很可能你的upvote方法是'''posts_upvote_path'''和'''posts_upvote_url'' –
@Matt:對於投票系統你可以嘗試'act_as_votable' gem根據您的要求,它很容易整合和使用。這是鏈接https://github.com/ryanto/acts_as_votable –