我是 Rails 新手,并试图为使用acts_as_votable gem 的问题获得支持。我收到以下错误消息,告诉我没有路线匹配:
No route matches [GET] "/questions/1/like"
这是我在 questions_controller.rb 中的投票方法:
def upvote
@question = Question.find params[:question_id]
@question.liked_by current_user
redirect_to @questions
end
我的 routes.rb 文件:
resources :comments do
resources :questions
member do
put "like", to: "questions#upvote"
end
end
和我的投票按钮:
<%= link_to "Upvote", like_question_path(@comment, @question, method: :put) %>
谢谢您的帮助!