本文介绍了act_as_votable gem 路由错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Rails 的新手,并试图为使用 act_as_votable gem 工作的问题获得赞成票.我收到以下错误,告诉我没有路由匹配:
i'm new to rails and trying to get upvotes for questions working using the acts_as_votable gem. I am getting the following error telling me i have no route matches:
No route matches [GET] "/questions/1/like"
这是我在 questions_controller.rb 中的 upvote 方法:
Here is my upvote method in my questions_controller.rb:
def upvote
@question = Question.find params[:question_id]
@question.liked_by current_user
redirect_to @questions
end
我的 routes.rb 文件:
My routes.rb file:
resources :comments do
resources :questions
member do
put "like", to: "questions#upvote"
end
end
和我的投票按钮:
<%= link_to "Upvote", like_question_path(@comment, @question, method: :put) %>
感谢您的帮助!
推荐答案
试试这个:
routes.rb
resources :comments do
resources :questions do
put "like", to: "questions#upvote"
end
end
点赞按钮:
<%= link_to "Upvote", comment_question_like_path(@comment, @question), method: :put %>
你需要正确的路径,并且link_to使用的方法在第二个参数之后.
You need the correct path, and also the method for link_to to use goes after the second parameter.
这篇关于act_as_votable gem 路由错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!