Reputation: 32140
I am trying to use the vote_fu gem and I encounter a problem that other have as well, but I can't solve this with others' solutions..
I don't think the problem is related directly to the gem.. but rather to some wrong route or a missing parameter..
I have a Msg model which I included the act_as_voteable
.
For the User Model I added act_as_voter
In the Msg controller I added
def votefor
@msg= Msg.find(params[:id])
current_user.vote_for(@msg)
redirect_to :back
end
In routes:
resources :msgs do
member do
post :votefor
end
end
And to the show of Msg I added
<%= link_to "Vote Up", votefor_msg_path(@msg), :method => :post %>
But when I click on the link created I get
Routing Error
No route matches [GET] "/msgs/1/votefor"
Why does it 'GET' instead of 'POST'? What am I missing?
Upvotes: 0
Views: 337
Reputation: 1581
I think its very late to answer this question & I mostly think you must have figured it out... I ran into the same issue & I understood the reason why..
This is a sample comment from routes.rb
# Sample resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
the post 'toggle'
here is not the post-controller but :method => 'post'
link_to default uses :method => 'get'
but you can override it using :method => 'post'
if u use link_to
.. in the example without :method => 'post'
your routing should be
resources :msgs do
member do
get :votefor
end
end
Hope this helps!
Update:
For the doubt you have:
link_to with a :method => :post
use this
<%= link_to "Vote Up", votefor_msg_path(@msg), :method => :post %>
and in the routes it should be
resources :msgs do
member do
post :votefor
end
end
the post :votefor .. is :method => :post not the posts controller.
Do check for brady8's answer
Upvotes: 1