Skip to content
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

Destroy link does not work #1643

Closed
sedubois opened this issue May 11, 2020 · 12 comments · Fixed by #1690
Closed

Destroy link does not work #1643

sedubois opened this issue May 11, 2020 · 12 comments · Fixed by #1690
Labels
bug breakages in functionality that is implemented frontend-pipeline Webpacker vs Sprockets

Comments

@sedubois
Copy link
Contributor

What were you trying to do?

I want to destroy a record using the red "Destroy" link on the index view.

  • What did you end up with (logs, or, even better, example apps are great!)?

Instead it simply shows the record, as if a GET was sent instead of DELETE, and so there is no way to delete the record.

  • What versions are you running?
@sedubois sedubois added the bug breakages in functionality that is implemented label May 11, 2020
@nickcharlton
Copy link
Member

Is this perhaps related to removing jquery-ujs in #1618?

My understanding is that that's what ensures the correct request occurs, but I'm sort of surprised it doesn't fallback

@sedubois
Copy link
Contributor Author

sedubois commented May 12, 2020

@nickcharlton I confirm that by switching back to 3468644 (commit before the merge of #1618) the issue disappears.

@nickcharlton
Copy link
Member

Damn. If you make sure rails-ujs is loaded for the Administrate Engine, does that help? I'm wondering if it's a Rails Engine compatibility issue.

I'm also surprised we didn't catch this on CI, so that's something to look at too.

@sedubois
Copy link
Contributor Author

@nickcharlton I'm quite illiterate with this rails-ujs thing and rails engines, would you mind giving a bit more guidance?

@sedubois
Copy link
Contributor Author

BTW (TL = Turbolinks),

The need for UJS is gone with TL6

Plan is to have TL6 out ~late summer/early fall

https://discuss.rubyonrails.org/t/turbolinks-doesnt-handle-render/74772/3
https://discuss.rubyonrails.org/t/turbolinks-doesnt-handle-render/74772/5

Maybe the change to rails UJS imports can be reverted and then upgrade to TL6 when available?

@nickcharlton
Copy link
Member

I think we might just about know as much as each other here, but it seems like we expected the ujs removal to not be a problem as it was pulled in elsewhere so no longer needed. As for Rails engines, this sounds very similar to issues we've been having with the asset pipeline/webpacker and needing to do extra work to pull in dependencies.

Can you try on Rails 6.1? (or, perhaps replicate it with a failing test so we can see it on CI?)

@sedubois
Copy link
Contributor Author

sedubois commented May 12, 2020

I don't have time to dig deeper with Rails 6.1 right now but for what it's worth the issue persists when commenting out turbolinks.start() in my admin JS pack.

@pablobm
Copy link
Collaborator

pablobm commented May 14, 2020

I looked into why this test passes with rack-test. I really didn't expect what I found...

Turns out that Capybara tries to be clever about data-* attributes used by Rails. Therefore, when it sees the link to delete a record, it issues a DELETE request instead of the expected GET. This apparently has been the case for a long time: teamcapybara/capybara#184

I created a branch where I tell Capybara not to be clever: master...pablobm:demo-clever-capybara It results in 3 spec failures.

I have also added this to https://github.com/thoughtbot/administrate/projects/1, and created a milestone "Release blockers". We should fix this before we release another version.

@nickcharlton
Copy link
Member

Oh! Yikes, that's very unexpected. I did not know it did that by default.

What's the best thing to do here, given those failures?

@pablobm
Copy link
Collaborator

pablobm commented May 14, 2020

No idea 😓 I'm going to have to dive into the whole Rails/JS stuff to try clarify all this...

@pablobm pablobm added the frontend-pipeline Webpacker vs Sprockets label Jun 11, 2020
@pablobm pablobm mentioned this issue Jun 25, 2020
4 tasks
nickcharlton added a commit that referenced this issue Jun 26, 2020
In #1618, we removed the explicit include of `jquery_ujs` as it should
no longer be necessary. Alas, this broke the ability to destroy items.

This wasn't caught by the tests because Capybara tries to be clever with
these links, sending the `DELETE` directly instead of clicking on the link. We
disable this here and switch the specs to use the JS driver so that
we're actually testing the functionality (it can't pass without).

Adding the include of `jquery_ujs` solves this for now, unblocking us
from having a release for lots of other features and allows us to
revisit this problem again (in a way that we'll catch it this time!).

Fixes #1643.
nickcharlton added a commit that referenced this issue Jun 30, 2020
In #1618, we removed the explicit include of `jquery_ujs` as it should
no longer be necessary. Alas, this broke the ability to destroy items.

This wasn't caught by the tests because Capybara tries to be clever with
these links, sending the `DELETE` directly instead of clicking on the link. We
disable this here and switch the specs to use the JS driver so that
we're actually testing the functionality (it can't pass without).

Adding the include of `jquery_ujs` solves this for now, unblocking us
from having a release for lots of other features and allows us to
revisit this problem again (in a way that we'll catch it this time!).

Fixes #1643.
@mcmaddox
Copy link

mcmaddox commented Oct 9, 2022

Can this issue be reopened? I'm still experiencing this issue in v0.18.0 (Rails 6.1 with Turbo & Webpacker).

I added require("@rails-ujs") to the administrate.js pack, but the default link_to with method: :delete in show.html.erb view isn't recognized & sends a GET request that reloads the page instead of presenting the confirm dialog. I didn't think adding rails-ujs to the administrate.js pack was necessary since it's already in the application.js pack for my app.

Has anyone else resolved this issue in Rails 6.1?

@pablobm
Copy link
Collaborator

pablobm commented Oct 20, 2022

Hello @mcmaddox, thank you for reporting. Would you be able to share your administrate.js pack? I am not well versed on asset management, so I just created a Rails 6.1.7 app to check, and mine looks like this:

// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"

Rails.start()
Turbolinks.start()
ActiveStorage.start()

So there's no require, and the correct name of the package is @rails/ujs (instead of @rails-ujs). Could it be that the problem lies there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented frontend-pipeline Webpacker vs Sprockets
Projects
None yet
4 participants