I am using the acts_as_votable plugin and I keep getting this error:
No route matches {:action=>"upvote", :controller=>"posts", :id=>nil} missing required keys: [:id]
I am following the answer from this SO question: acts_as_votable thumbs up/down buttons
I tried adding .id to the view as suggested here: Getting a strange error on my routes, "missing required keys" rails 4 but then I get this error:
undefined method `id' for nil:NilClass
here is my code:
post_controller:
def upvote
@post = Post.find(params[:id])
@post.liked_by current_user
redirect_to @post
end
routes:
resources :posts do
member do
get 'like' => 'posts#upvote', as: :upvote
end
end
view:
<% @posts.each do |post| %>
<%= post.user.name %><BR><BR>
<%= post.post_content %><BR><BR>
<%= link_to "like", upvote_post_path(@post), method: :put %>
<% end %>