rails 4.2 link_to method: No route matches [POST] -


i'm trying construct link_to method: :delete call destroy method in users controller:

<%= link_to 'disable token', user_path(user), method: :delete, data: { confirm: 'are sure?'} %> 

which generates html looks like:

<a data-confirm="are sure?" rel="nofollow" data-method="delete" href="/users/6">disable token</a> 

my application.js file has:

//= require jquery                                                                                                                                             //= require jquery_ujs   

and, in fact, know javascript loaded , doing supposed to, because generates 'are sure?` alert dialog.

however, when following link following:

no route matches [post] "/users/9" 

and indeed there no such route, because routes are:

users_path  /users(.:format)    users#index user_path   delete  /users/:id(.:format)    users#destroy 

the mystery (to me) why rails doing post route in first place? you'll note url correct ("/users/9") http verb not: post.

the parameters of request getting set:

{"_method"=>"delete",  "authenticity_token"=>"vcavjf1/f9mwjni4gptertdiyjkobniof0hiqvf+3bvmzuniohymm2z3w2sqsljqj11sz/tiht78aa9 } 

here can see _method key being set delete should be, why routing error?!?

i'm stumped.

edit: if change link_to call include remote: true rails routes proper route! so, "fix" i've changed controller use ujs, don't because, well, far can tell had before should work!

here link_to call sends proper delete request js:

<%= link_to 'disable token', u, method: :delete, data: { confirm: 'are sure?'}, remote: true %>                                                                                                                                                                                   

just try explicitly stating controller action , method (note @user.id example, may referencing differently) url_for:

<%= link_to 'disable token', url_for(action: :destroy, id: @user.id), method: :delete, data: { confirm: 'are sure?'} %> 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -