Search code examples
ruby-on-railsrubyruby-on-rails-3votingvoting-system

No route matches {:action=>"vote_up", :controller=>"posts"} error for thumbs_up


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.


Solution

  • 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.