我正在尝试对使用acts_as_votable gem 的问题进行投票。我收到一条错误消息:
Couldn't find Question with id=like
此 URL 不显示问题 ID:
/comments/1/questions//like
当我手动输入问题ID时,它给了我这个:
No route matches [GET]
这是我的投票方法:
def upvote
@question = Question.find params[:question_id]
@question.liked_by current_user
redirect_to @questions
end
这是 routes.rb 文件:
resources :comments do
resources :questions do
put :upvote, :on => :member, :as => :like
end
end
和upvote按钮:
<%= link_to "Upvote", comment_question_like_path(@comment, @question), method: :post %>
Rake 路线将 comment_question_like_path 显示为有效路线,因此这不是问题。谢谢你的帮助!