我有一個簡單的帖子模型,標題爲:字符串和評分:整數,我想添加評分帖子的能力。到目前爲止,我有幫助:在Rails中爲現有帖子模型添加評分
#Post controller
def increase
@post = Post.find(params[:id])
@post.increment! :rating
flash[:notice] = "Thanks for your rating."
redirect_to @post
end
#Post show
<%= link_to "Rating", increase_post_path %>
#Routes
map.resources :posts, :member => { :increase => :put }
當我點擊評分,我得到未知的行動。當我添加@ post.increment時,我可以提高評分! :評級更新,但不是當我創建我自己的方法。任何建議?
這就是我做錯了,謝謝。 –