Reputation: 8759
I am using https://github.com/ryanto/acts_as_votable gem. I am an error:
NoMethodError in PostsController#index - undefined method `upvote_post_path' for #<#:0x007fb5010f34b8>
Basically what I did is put a link for specific task in my view.
<%= link_to "upvote", upvote_post_path(post), method: put %>
Similar link:
<%= link_to "edit", edit_post_path(post)%>
inside the same view works just fine. Here is my controller part of these two methods:
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
These are my routes:
resources :users
resources :posts do
put 'upvote', to: 'posts#upvote'
end
I am unable to figure out where is the issue.
Upvotes: 0
Views: 54
Reputation: 947
Your call in View for upvote_post_path
should be:
post_upvote_path(post)
instead of upvote_post_path(post)
should look like this:
<%= link_to "upvote", post_upvote_path(post), method: put %>
Upvotes: 4
Reputation: 3323
As per rake routes
<%= link_to "upvote", post_upvote_path(post), method: put %>
Upvotes: 1
Reputation: 1045
Your call to route should have been
post_upvote_path(post)
instead upvote_post_path(post)
Upvotes: 1