The other solutions here did not work, so I am posting a new question. I am using acts_as_votable for up and down voting on links, but when I try to actually vote I get the error:
No route matches [GET] "/links/1/like"
This is what my view looks like:
<%= link_to like_link_path(link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-up"></span>
Upvote
<%= link.get_upvotes.size %>
<% end %>
<%= link_to dislike_link_path(link), method: :put, class: "btn btn-default btn-sm" do %>
<span class="glyphicon glyphicon-chevron-down">
Downvote
<%= link.get_downvotes.size %>
<% end %>
And this is what my routes look like:
resources :links do
member do
put "like", to: "links#upvote"
put "dislike", to: "links#downvote"
end
end
I see that my client is trying to access the get method, but I explicitly call method: :put
in my index.html.erb file.
Do you know why it is trying to access get and how I can override that?
It turns out that the answer was related to JQuery. I was getting an Uncaught ReferenceError: jQuery is not defined
error and so what I did was include JQuery outright in my application.html.erb file.
You have to put this ahead of all your other scripts.
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
After that, the voting began to work