0

I followed the steps indicated in this answer for setting up thumbs_up

https://stackoverflow.com/a/4963297/1643048

However I keep getting this error and have no idea how to fix it:

No route matches {:action=>"vote_up", :controller=>"posts", :id=>nil}

Can anyone help?

UPDATE:

exact error-

Routing Error

No route matches {:action=>"vote_up", :controller=>"posts", :id=>nil}

Try running rake routes for more information on available routes.

config/routes.rb:

Projectmadrone::Application.routes.draw do
  devise_for :admins
  #devise_for :users
  devise_for :users do get '/users/sign_out' => 'devise/sessions#destroy' end
  resources :posts do
    member do
        post :vote_up
       end
     end
  root :to => 'posts#index'
 end

my view: app/views/posts/index.html.erb

<li><%= link_to('vote for this post!', vote_up_post_path(@post), :method => :post) %></li>
Community
  • 1
  • 1
amritha
  • 75
  • 1
  • 6
  • Could you post the exact content of your "config/routes.rb" as well as the context/sorrounding lines of the server-log regarding this error? – spaudanjo Sep 03 '12 at 19:51

1 Answers1

0

Your @post-variable seems to be nil. Propably because you are using it in the index-view instead of the show-view. So you should try to put the link_to-code into the app/views/posts/show.html.erb.

spaudanjo
  • 764
  • 7
  • 13
  • Unfortunately, that does not fix the problem, it is still giving me the same error – amritha Sep 03 '12 at 20:15
  • Perhaps you could push the whole code up to github and send the link then or at least post the posts_controller.rb as well. – spaudanjo Sep 03 '12 at 20:17
  • OH, i understand why my @post is nil!! – amritha Sep 03 '12 at 20:18
  • 1
    It won't let me post right now because I'm not allowed to answer my own question for 8 hours after posting... But basically all I had to do was change @post to post in the link_to call because it was executing within a block. – amritha Sep 03 '12 at 20:28
  • Actually I don't know if this actually fixes the problem, because now when I click on the vote, it leads to a blank page – amritha Sep 03 '12 at 20:31