我试图在我的应用程序中提出向上投票/向下投票的方法,但我遇到了一个无方法错误。
这是我的选民表格:
<div>
<div class= 'pull-left'>
<div><%= link_to " ", post_up_vote_path(post), class: 'glyphicon plyphicon-chevron-up', method: :post %></div>
<div><strong><%= post.points %></strong></div>
<div><%= link_to " ", post_down_vote_path(post), class: 'glyphicon plyphicon-chevron-up', method: :post %></div>
</div>以下是我的路线:
App::Application.routes.draw do
devise_for :users
resources :users
resources :topics do
resources :posts, except: [:index] do
resources :comments, only: [:create, :destroy]
post '/up-vote' => 'votes#post_up_vote', as: :up_vote
post '/down-vote' => 'votes#post_down_vote', as: :down_vote
end
end
get 'about' => 'welcome#about'
root to: 'welcome#index'
end下面是我的部分调用:
<%= render partial: 'votes/voter', locals: { post: post } %>现在,我不认为我的部分呼叫或我的选民部分呼叫有任何问题,因为在我尝试路由它之前,一切都正常。
发布于 2014-12-04 09:43:32
首先,你需要稍微改变一下你的路线。
resources :posts, except: [:index] do
resources :comments, only: [:create, :destroy]
post 'upvote', on: :member
post 'downvote', on: :member
end这些是成员路由而不是收集路由的原因是,它们适用于帖子集合中的特定成员...单个Post。
然后,您需要在终端中运行命令rake routes,以查看适当的路径方法。它应该是这样的
upvote_post_path(:id)这需要将一个对象传递给in..so,在你的视图中你可以像现在一样使用它。
upvote_post_path(post)https://stackoverflow.com/questions/27284450
复制相似问题