我已经安装了' acts_as_votable'宝石,但身份证不起作用。 这是我得到的:
undefined method `like_answer_path' for #<#<Class:0x007f882266a948>:0x007f8824a012d0>
我的routes.rb:
Rails.application.routes.draw do
...
resources :questions do
resources :answers do
member do
put "like", to: "answers#upvote"
end
end
end
...
end
answers_controller.rb:
class AnswersController < ApplicationController
...
def upvote
@answer = Answer.find(params[:id])
@answer.upvote_by current_user
redirect_to question_path(@question)
end
...
end
_answer.html.slim
.answer id="answer-#{answer.id}"
.contents= answer.contents
.details
' Answered on
= l(answer.created_at, format: :long)
' by
= link_to answer.user, user_path(answer.user)
= link_to "upvote", like_answer_path(@answer), method: :put
答案 0 :(得分:1)
类的未定义方法`like_answer_path':0x007f882266a948
当你运行rake routes
时,你会得到
like_question_answer PUT /questions/:question_id/answers/:id/like(.:format) answers#upvote
所以你的link_to
应该是
= link_to "upvote", like_question_answer_path(@question,@answer), method: :put