Ezequiel Ramiro Ezequiel Ramiro - 2 years ago 79
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
method instead of

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

makes no sense to me..


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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download