我正在使用https://github.com/ryanto/acts_as_votable寶石。我是一個錯誤:方法無法從視圖中讀取
NoMethodError in PostsController#index - undefined method `upvote_post_path' for #<#:0x007fb5010f34b8>
基本上我所做的是在我的視圖中爲特定任務放置一個鏈接。
<%= link_to "upvote", upvote_post_path(post), method: put %>
類似鏈接:
<%= link_to "edit", edit_post_path(post)%>
同一視圖內工作得很好。下面是這兩個方法我的控制器部分:
def destroy
@post = current_post
@post.destroy
flash[:success] = "Post deleted"
redirect_to request.referrer || root_url
end
def upvote
@post.liked_by current_user
end
這是我的路線:
resources :users
resources :posts do
put 'upvote', to: 'posts#upvote'
end
我無法找出其中的問題。
什麼是你的'rake routes'輸出? – sureshprasanna70
@ sureshprasanna70我更新了耙路徑輸出截圖的問題。 – Kunok
它應該是post_upvote_path(後) – LHH