1

Can anyone tell me why the following is not working in Rails 7?

<%= link_to "delete", user, data: {  turbo_method: :delete } %>

The expected action was a DELETE request routed to the destroy action from the UsersController. The result was a GET request (GET /users/1) routed to the show action.

I have also tried:

data: { turbo: true, turbo_method: :delete }
data: { "turbo-method": :delete }
data: { "turbo_method": :delete }  

I have resources :users in routes.rb with rails routes indicating:

user GET    /users/:id(.:format)     users#show                                                                    
     PATCH  /users/:id(.:format)     users#update                                                                      
     PUT    /users/:id(.:format)     users#update                                                                         
     DELETE /users/:id(.:format)     users#destroy      

Running:

ruby 3.2.2 
rails 7.1.1
turbolinks 5.2.1

In previous version of rails this was simply method: :delete, but apparently in Rails 7 the more complicated the better.

5
  • have you installed turbo/stimulus? stackoverflow.com/a/74015122/1081668 Commented Nov 28, 2023 at 6:16
  • Do I need to install gems for basic REST actions to work?? Commented Nov 28, 2023 at 7:33
  • yes, because Rails 7 uses Turbo :) Or you may need to remove Turbo and use the old way. Commented Nov 28, 2023 at 9:35
  • perhaps worth mentioning is that I have turbolinks installed. Is this deprecated in rails 7? Or can I install the turbo gem next to it? Commented Nov 28, 2023 at 18:58
  • it's default when you create new Rails app. Check your Gemfile to see if it has turbo-rails gem Commented Nov 29, 2023 at 9:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.