我試圖實現acts_as_votable寶石如本本教程
https://www.youtube.com/watch?v=7-1HCWbu7iU沒有路由匹配[GET]「/鏈接/ 1 /像」與acts_as_votable
似乎一切都workigng很好,除了當我點擊在給予好評或downvote,我得到這個錯誤:
No route matches [GET] "/links/1/like"
這是給予好評/ downvote函數的代碼
<span class="upvote">
<%= link_to like_link_path(link), method: :put, class: "upvote-image" do %>
<% end %>
</span>
氏s是的routes.rb文件:
resources :links do
member do
put "like", to: "links#upvote"
put "dislike", to: "links#downvote"
end
resources :comments
end
這裏是給予好評,並在links_controller downvote行動
def upvote
@link = Link.find(params[:id])
@link.upvote_by current_user
redirect_to :back
end
def downvote
@link = Link.find(params[:id])
@link.downvote_by current_user
redirect_to :back
end
關於如何解決這個任何想法?
這是'link_to'方法的不正確使用。我們不應該寬恕這一點。 –