In Rails 7, if you are using button_to helper method to make API calls and it's not working asynchronously but instead goes to the given URL, that means you've messed up some configuration somewhere. A button_to is used like this:

<%= button_to "Delete User", admin_activate_user_path(user), data: { turbo_method: "post", turbo_confirm: "Are you sure you want to delete this user?" }, class: 'btn btn-info btn-sm' %>

which creates a form that is submitted asynchronously. If it's not working as expected, check if turbo-rails javascript library is included in the application.js file or not. If not, add the following to it:

import "@hotwired/turbo-rails"

Rails 7 includes Hotwire and Turbo Rails as default options. If you're not using Rails 7, you may need to include the turbo-rails gem and install it. Additionally, you may need to include the turbo javascript in your layout file:

<%= javascript_include_tag 'turbo' %>

Once that is done, the button_to should be working as expected.