1

I'm trying to implement the thumbs_up gem into my app and I keep getting this error even though I have a route for the vote_up action

My posts controller looks like

   def vote_up
     begin
       current_user.vote_for(@post = Post.find(params[:id]))
       render :nothing => true, :status => 200
     rescue ActiveRecord::RecordInvalid
       render :nothing => true, :status => 404
     end
   end

My route looks like

   resources :posts do
     get :vote_up, :on => :member
     resources :comments
   end

I don't know what the problem is, if anyone could help me or point me to a tutorial to use the thumbs_up gem that would be great.

Michael Peralta
  • 293
  • 5
  • 18

1 Answers1

2

The problem is that you're requesting vote_up without an id for a post. Just looking at your controller:

current_user.vote_for(@post = Post.find(params[:id]))

Yet I do not see any id field in your request. The problem lies in your view.

Jordan Scales
  • 2,687
  • 4
  • 28
  • 37
  • Agreed. The `vote_up` route is on a member resource. The error is because you're not passing the `id` parameter along to this route. – Ryan Bigg May 24 '12 at 05:17
  • @Jordan Scales: What should the corrected code look like? How do you put the id into the request? – gbutters Apr 09 '16 at 16:46