簡體   English   中英

路由錯誤Ruby on Rails —投票系統

[英]Routing Error Ruby on Rails — Voting system

我正在使用acts_as_votable gem對我的博客評論實施投票系統。

但是,我遇到路由錯誤: no route matches. missing required keys: [:id] no route matches. missing required keys: [:id]

  #routes.rb
  resources :articles do
     resources :comments do
        member do
            put "like", to: "comments#upvote"
        end
    end
  end

# comments controller
def upvote
    @comment.upvote
    redirect_to :back
end

# comments/show.html.haml
= link_to like_article_comment_path(@comment), method: :put do
   = @comment.get_upvotes.size

如果您使用rake routes | grep like rake routes | grep like (添加該路線),您將獲得:

like_article_comment PUT    /articles/:article_id/comments/:id/like(.:format)  comments#upvote

因此,您在鏈接中缺少第一個參數- :article_id 應該:

= link_to like_article_comment_path(@article, @comment), method: :put do
  = @comment.get_upvotes.size

還要在您的upvote方法中添加@article邏輯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM