我有一个带有 title:string 和 rating:integer 的简单帖子模型,我想添加对帖子进行评分的功能。到目前为止我有
#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 时,我可以提高评分!:rating 更新,但不是在我创建自己的方法时。有什么建议吗?