lundi 23 janvier 2023

Ruby on rails link_to delete method doesn't work

I used this code to delete a form in my app but it doesn't work

<td><%= link_to 'Destroy', resource, method: :delete, data: { confirm: 'Are you sure?' } %></td>

When I click it displays the information entered in the form. I already tried to solve the problem with jquery but it didn't work.

I have this in my terminal:

> Started GET "/resources/2" for 127.0.0.1 at 2023-01-23 10:43:44 +0100
Processing by ResourcesController#show as HTML
  Parameters: {"id"=>"2"}
  Resource Load (15.4ms)  SELECT "resources".* FROM "resources" WHERE "resources"."id" = $1 LIMIT $2  [["id", 2], ["LIMIT", 1]]
  ↳ app/controllers/resources_controller.rb:63:in `set_resource'
  User Load (5.0ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering layout layouts/application.html.erb
  Rendering resources/show.html.erb within layouts/application
  Rendered resources/show.html.erb within layouts/application (Duration: 3.4ms | Allocations: 412)
  Rendered layout layouts/application.html.erb (Duration: 30.8ms | Allocations: 2972)
Completed 200 OK in 291ms (Views: 43.5ms | ActiveRecord: 121.3ms | Allocations: 10816)


Started GET "/resources" for 127.0.0.1 at 2023-01-23 11:05:41 +0100
Processing by ResourcesController#index as HTML
  User Load (23.4ms)  SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Rendering layout layouts/application.html.erb
  Rendering resources/index.html.erb within layouts/application
  Resource Load (4.6ms)  SELECT "resources".* FROM "resources"
  ↳ app/views/resources/index.html.erb:16
  Rendered resources/index.html.erb within layouts/application (Duration: 17.5ms | Allocations: 1379)
  Rendered layout layouts/application.html.erb (Duration: 46.8ms | Allocations: 3317)
Completed 200 OK in 476ms (Views: 59.7ms | ActiveRecord: 181.9ms | Allocations: 9944)

Can anyone tell me how to solve this problem?

Thank you!

Aucun commentaire:

Enregistrer un commentaire