1

I'm new to Rails and can't seem to figure this out

Every time I click the link it doesn't delete the article, it just takes me to the show view. Not sure why this is happening. Here is my code for the link:

 <%= link_to 'delete', article_path(article.id), method: :delete, data: { confirm: "Are you sure?" } %>

my rails server shows a GET request even though I specified the method (I think):

Started GET "/articles/1" for ::1 at 2020-09-07 10:05:13 -0700
Processing by ArticlesController#show as HTML
  Parameters: {"id"=>"1"}
  Article Load (0.7ms)  SELECT "articles".* FROM "articles" WHERE "articles"."id" = ? LIMIT ?  
  [["id", 1], ["LIMIT", 1]]
  ↳ app/controllers/articles_controller.rb:46:in `set_article'
  Rendering articles/show.html.erb within layouts/application
  Rendered articles/show.html.erb within layouts/application (Duration: 4.0ms | Allocations: 321)
[Webpacker] Everything's up-to-date. Nothing to do
  Rendered layouts/_flashMessages.erb (Duration: 0.2ms | Allocations: 18)
  Rendered layouts/_navBar.html.erb (Duration: 0.1ms | Allocations: 5)
Completed 200 OK in 123ms (Views: 96.9ms | ActiveRecord: 0.7ms | Allocations: 5344)

I can't figure out why. Any help is appreciated. Thanks!

Tristan
  • 11
  • 1
  • 1
    Does this answer your question? [Rails' link\_to method: GETing when it should DELETE](https://stackoverflow.com/questions/7465919/rails-link-to-method-geting-when-it-should-delete) – Eyeslandic Sep 07 '20 at 17:24

1 Answers1

0

I had the same issue in Rails 6. It seems that a wrong version of jquery can cause this. Somehow @rails/ujs stopps working correctly if you install the wrong jquery version.

If you have no errors in your code you can try to fix it by deleting the jquery gem and add jquery through yarn (my question concering this topic)

Spinshot
  • 275
  • 2
  • 12