2

I'm trying to implement acts_as_votable gem as shown in this this tutorial
https://www.youtube.com/watch?v=7-1HCWbu7iU

Seems everything is workigng fine, except when I click on upvote or downvote, I get this error:

No route matches [GET] "/links/1/like"

This is the code for upvote / downvote function

<span class="upvote">
          <%= link_to like_link_path(link), method: :put, class: "upvote-image" do %>
          <% end %>
</span>

This is the routes.rb file:

  resources :links do
    member do
      put "like", to:    "links#upvote"
      put "dislike", to: "links#downvote"
    end

    resources :comments
  end

Here are the upvote and downvote actions in links_controller

def upvote
    @link = Link.find(params[:id])
    @link.upvote_by current_user
    redirect_to :back
  end

  def downvote
    @link = Link.find(params[:id])
    @link.downvote_by current_user
    redirect_to :back
  end

Any idea on how to resolve this?

idjuradj
  • 1,355
  • 6
  • 19
  • 31

3 Answers3

0

Looks like the problem is down to your link having a GET method, rather than PUT:

No route matches [GET] "/links/1/like"

I can only surmise that your link_to code is not written correctly:

<span class="upvote">
   <%= link_to like_link_path(link), method: :put, class: "upvote-image" %>
</span>

Your other code looks good. If you test this, the best thing to do will be to show the pure HTML for the link in your question - this will give us the ability to see whether it's being rendered correctly.

Richard Peck
  • 76,116
  • 9
  • 93
  • 147
0

I found an answer for this, and I'm posting it here in case there are others with the same problem.

I'm developing on Windows. I had problems with javascript, and followed this solution here: https://stackoverflow.com/a/31972253/1690091

This removed the javascript related errors that were popping all over the place, but this is NOT the solution. This simply removed js from my app.

The real solution is here: https://stackoverflow.com/a/28331807/1690091

You need to use a proper version of coffee script, that's compatible with Windows.

To sum things up:

js file was missing from my app, and therefore //= require jquery_ujs was also missing, and that's why all of my links were being called as GET.

@Rich Peck, Thanks for your help.

Community
  • 1
  • 1
idjuradj
  • 1,355
  • 6
  • 19
  • 31
-1

Try this

<span class="upvote">
  <%= link_to like_path, method: :put, class: "upvote-image" do %>
  <% end %>
</span>
joeyk16
  • 1,357
  • 22
  • 49