0

A rails 4 app. A simple question: why does this genereate a GET request?

   <%= link_to("fdsfds", some_delete_path, method: :delete, data: { confirm: "Are you sure fdsfds?" }) %>

routes:

delete '/some-path/some-path123' => 'controller123#method123', as :some_delete

All query libraries are included properly.

html:

<a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/fdsfdsfds">dsfdsfds</a>

error:

No route matches [GET] "/fdsfdsfdss"
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205

3 Answers3

0

Your code is good, but your javascript include is probably not. Check that your application.js is including the correct libraries. What you may be missing is 'jquery_ujs' which is what handles confirmation dialogs and non-Get requests.

Here's mine with query.

//= require jquery
//= require jquery_ujs
//= require_tree .

Without the javascript library, your link will be a GET request.

Carson Cole
  • 4,183
  • 6
  • 25
  • 35
  • It should still build the correct link looking at link_to docs, http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html (under Options) – Josh Brody Jan 10 '16 at 22:06
0

I realize this isn't an answer, but instead a "how do I go about debugging this?"

What does your inspector show? Does it show the request as a DELETE? If no, continue.

Add this to the very bottom of your routes path, update the link_to, and check your inspector if it sends a DELETE request?

controller:

def d abort end

routes:

match '/d' => 'posts#d', :via => [:delete]

view:

<%= link_to 'delete', '/d', :method => :delete %>

There may be some conflicting route, which while highly unlikely, there are a lot of moving parts which sometimes cause finicky errors.

If that doesn't answer your question, can you post your routes and view, and perhaps a screenshot of your inspector?

Josh Brody
  • 5,153
  • 1
  • 14
  • 25
0

If anyone comes here that uses the bootstrap (v4) gem and always ignored the tether warning in development: You actually need to add the tether gem as advised.

That error stops executing the current js file. If all js files are seperate (as they are in development) this doesn't stop the data-method js part getting executed. In production all js is concat into a single file and thus it won't execute the rest of the file which likely contains the data-method code.

rndstr
  • 777
  • 8
  • 14