Reputation: 215
I have a render on a page show view
This direct to the following code
<div>
<div><%= link_to " ", 'post_up_vote_path(post)', class: 'glyphicon glyphicon-chevron-up', method: :post %></div>
<div><strong><%= post.points %></strong></div>
<div><%= link_to " ", 'post_down_vote_path(post)', class: 'glyphicon glyphicon-chevron-down', method: :post %></div>
</div>
But now when I click the upbutton i get the following error:
Couldn't find Post with 'id'=post_up_vote_path(post)
What's going wrong?
My routes are set up like this
resources :post, only: [] do
resources :comments, only: [:create, :destroy]
post '/up-vote' => 'votes#up_vote', as: :up_vote
post '/down-vote' => 'votes#down_vote', as: :down_vote
end
And my controller variables are
def show
@post = Post.find(params[:id])
@topic = Topic.find(params[:topic_id])
@comments = @post.comments
end
Upvotes: 0
Views: 64
Reputation: 176412
Notice how you call the link_to
<%= link_to " ", 'post_up_vote_path(post)', class: 'glyphicon glyphicon-chevron-up', method: :post %>
The second argument is wrapped within apex, making it a string. That means the route is generated with the 'post_up_vote_path(post)'
interpreted as String
id.
Assuming the route definition is correct, it should be
<%= link_to " ", post_up_vote_path(post), class: 'glyphicon glyphicon-chevron-up', method: :post %>
The same applies to the corresponding down link.
Upvotes: 3