act_as_votable ジェムを使用して、質問に対する賛成票を獲得しようとしています。次のようなエラーが表示されます。
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
および賛成ボタン:
<%= link_to "Upvote", comment_question_like_path(@comment, @question), method: :post %>
Rake ルートは comment_question_like_path を有効なルートとして表示するため、問題はありません。助けてくれてありがとう!