Ezequiel Ramiro Ezequiel Ramiro - 6 months ago 22
Ruby Question

:method put: not working instead Get method

So I am trying to use the following route:

<%= link_to like_post_path(@post), :method => :put do %>


But I don't know why is using
GET
method instead of
PUT


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


makes no sense to me..

myroutes.rb:

resources :posts do
member do
put "like" => "posts#upvote"
put "dislike" => "posts#downvote"
end

Answer

You are using correct format and your code is should generate something like this:

<a data-method="put" href="...">

From your routes error message we can conclude that it is not being sent using POST with _method=put params. So, the problem must be that you did not include jQuery and Rails jQuery extension javascript files.

An easy fix would be to include application.js file (jquery and rails js extension are included by default) in your page.