-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rails 7 data-confirm not working for User deletion #5448
Comments
Can you try this
|
Having a similar issue on Rails 7.0.0. Can confirm that |
Also as a side-note, the |
ami no me funciona y estoy trabajando con esa version de rails 7 los men sajes de confirmacion <%= link_to "Salir", destroy_user_session_path, form: { data: { turbo_confirm: "Are you sure?" } },:method => :delete, class: "salir"%> |
None of the above is working for me. and I am using rails 7.0.4 |
nothing worked with me The browser keeps refreshing and does nothing
also with this
|
ruby 3.1.0
|
Try this:
|
ruby 3.1.2 |
Stumbled upon this while trying to fix a similar issue. https://stackoverflow.com/a/70482989/195509 solved it for me with:
|
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
Treat `:turbo_stream` request format as a navigational format, much like HTML, so Devise/responders can work properly. Allow configuring the `error_status` and `redirect_status` using the latest responders features, via a new custom Devise responder, so we can customize the both responses to match Hotwire/Turbo behavior, for example with `422 Unprocessable Entity` and `303 See Other`, respectively. The defaults aren't changing in Devise itself (yet), so it still responds on errors cases with `200 OK`, and redirects on non-GET requests with `302 Found`, but new apps are generated with the new statuses and existing apps can opt-in. Please note that these defaults might change in a future release of Devise. PRs/Issues references: #5545 #5529 #5516 #5499 #5487 #5467 #5440 #5410 #5340 #5542 #5530 #5519 #5513 #5478 #5468 #5463 #5458 #5448 #5446 #5439
The main branch should contain all that's necessary for fully working with Turbo now, which should fix this. A new version will be released soon, but feel free to test it out from the main branch in the meantime, and report back on any issues. Thanks. |
My setup is like this: I have this code in my form:
and it is working but if I changed it to
it does not and deletes the resource without warning. |
@Hombre2014 which version of turbo and turbo-rails are you using? See this note from the wiki:
With button_to and previous versions of turbo / turbo-rails, you might need to pass the data |
Yes, I saw this. I am using turbo-rails 1.3.3. |
@Hombre2014 Not sure that that could be then... is that the only button not working with confirmation? That's basically Turbo behavior so it should be nothing Devise specific. In my test app I have that exact same code: <%= button_to "Cancel my account", registration_path(resource_name),
data: { confirm: "Are you sure?", turbo_confirm: "Are you sure?" }, method: :delete %> And it works fine: CleanShot.2023-02-24.at.13.18.47.mp4Even if I remove the "confirm" and leave only "turbo_confirm", the HTML I get is this and it works: <button data-turbo-confirm="Are you sure?" type="submit">Cancel my account</button> Also using turbo-rails 1.3.3:
Sorry I can't be of more help there, confirmation is a Turbo feature and nothing Devise interferes with. |
OK, @carlosantoniodasilva I just try it with the code provided: I added the button_to option as well:
Now if I click the button_to it does delete it immediately without the alert. |
@Hombre2014 I pasted your code into my sample app and it worked: CleanShot.2023-02-24.at.13.46.54.mp4Can you get that confirmation to work on any other button in your app, that's not a devise related one? Like I mentioned, this doesn't seem to be an issue with Devise, but with the confirmation feature provided by Turbo, and something your app, not playing nicely. Just in case, I'd try the |
I get the same behavior as @odinsride, @Hombre2014 and many others here: when the default "Cancel my account" link/button is clicked then the user account is deleted right away. I tried:
Using ruby 2.7.2p137, rails 7.0.4.2, devise 4.9.0
Tested in Firefox and Chrome. P.S.: IMHO Adding in Devise an option to send a confirmation email to the user in order to delete his/her account would be better. |
The problem seems to be gone! I just removed the following statements from the file
However, IMHO adding in Devise an option to send a confirmation email to the user in order to delete his/her account would be good. |
Hi @Hombre2014, @lapser I think it may be that the version of @hotwired/turbo is not higher than 7.2.0. If you use jsbundling-rails, I want to know If you use importmap-rails, I want to know |
Based on the listed gem versions, it's using turbo-rails 1.4 which should have the latest Turbo I believe. That said, it does appear to be something with Turbo as the behavior to show a confirmation message and/or send a DELETE request is all Turbo behavior, nothing specific to Devise there. @lapser are you able to use confirm and/or method with other buttons / links that aren't Devise? Is Turbo navigation working fine across the app? I'd start there.
The confirmation is just a simple way to avoid a button click from triggering the Delete provided by Devise, you're able to change that behavior in your app if necessary. For example we added a password confirmation step. In any case, I'm going to consider this as a possible feature for the future. Thanks! |
This solution worked for me (version 7.0.4.3): |
This works for me: <%= link_to "Delete", coin, data: { turbo_confirm: "Are you sure?", turbo_method: :delete } %> where registration_path(resource_name) <=> coin (in my code)The error occurs because GEMFILE is using Hotwire Turbo Streams. Your "error" is associated with data: { confirm: "Are you sure?" }, which is fine for the default behavior WITHOUT Turbo Streams, that belongs to hotwire library. So the difference is related to the choice of approach and LIBRARY you are using in your application. If you are using Turbo Streams, the correct approach is the one above. |
Environment
Current behavior
When clicking the default "Cancel my account" link, the data-confirm is not triggering, and instead it is deleting the user account right away. I am using Rails 7 with turbo / stimulus / importmap, although I have
data-turbo
set tofalse
for my edit user form. Here is the form code:The
data: { confirm: "Are you sure?" }
bit does not seem to be doing anything in my setup.Expected behavior
Clicking the "Cancel my account" link prompts the user to confirm before their account is deleted.
The text was updated successfully, but these errors were encountered: