关于加个-的作法

看了学长们的logdown做了出来…… 首选在app/controllers/topics_controller.rb加一个def 像这样 def downvote @topic = Topic.find(params[:id]) @topic.votes.last.try(:destroy) redirect_to(topics_path) end 然后再打开app/topics/index.html.erb

Screen Shot 2016-09-22 at 2.34.30 PM.png 加上-1那行。

另一种作法 def downvote @topic = Topic.find(params[:id]) if @topic.votes.count > 0 @topic.votes.first.destroy else flash[:notice] = “The vote already is 0.” end redirect_to (topics_path) end