# Link\_to does not work with delete method when app is created with --skip-javascript

**URL:** <https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850>\
**Category:** General\
**Created:** [January 3, 2021, 7:13pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850 "2021-01-03T19:13:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![atillaa](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@atillaa](https://discuss.hotwired.dev/u/atillaa)\
**Post date:** [January 3, 2021, 7:13pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/1 "2021-01-03T19:13:22Z")

</div>

`<%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>`

does not work when application is created with `--skip-javascript`

but `button_to` works in any case

`<%= button_to 'remove', post, method: :delete %>`

is there a way to use `link_to`?

---

<div class="post-metadata">

**Author:** ![jonathanbruno](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/jonathanbruno/32/1215_2.png) [@jonathanbruno](https://discuss.hotwired.dev/u/jonathanbruno)\
**Post date:** [January 3, 2021, 9:05pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/2 "2021-01-03T21:05:03Z")

</div>

If I’m not mistaken the data-confirm option is part of rails ujs, which is not included when you skip the javascript

---

<div class="post-metadata">

**Author:** ![jacobdaddario](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/jacobdaddario/32/1183_2.png) [@jacobdaddario](https://discuss.hotwired.dev/u/jacobdaddario)\
**Post date:** [January 3, 2021, 9:53pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/3 "2021-01-03T21:53:53Z")

</div>

To add on to what @jonathanbruno said, the reason that `button_to` still works is because it does not require UJS to intercept the request. When using `button_to` with the `method` option, it creates a form with the button and this hidden field:

```auto
<input name='_method' value='delete' type='hidden' />

```

To my understanding, this hidden field is what allows the server to interpret the request as a delete request. I’m not sure if this happens at the Rack or Rails level, but it’s required since HTML doesn’t natively support `put` or `delete` requests.

If you dive into the source of Rails-UJS you can [find this file.](https://github.com/rails/rails/blob/master/actionview/app/assets/javascripts/rails-ujs/features/method.coffee) This is the source that allows for the use of `method` on `link_to`. This code shows that all it does is insert a form with the same hidden field that is generated with the button, and then it automatically submits it.

Hope this explanation helps. I definitely have had a lot of confusion about this in the past too.

---

<div class="post-metadata">

**Author:** ![mrhead](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/mrhead/32/120_2.png) [@mrhead](https://discuss.hotwired.dev/u/mrhead)\
**Post date:** [January 4, 2021, 3:39pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/4 "2021-01-04T15:39:59Z")

</div>

Even if you keep using rails-ujs, you won’t be able to create POST or DELETE links with Turbo. It won’t work: [https://github.com/hotwired/turbo-rails#compatibility-with-rails-ujs](https://github.com/hotwired/turbo-rails#compatibility-with-rails-ujs)

If you need to create a non-GET link, then you need to use `button_to` and style the button as a link.

---

<div class="post-metadata">

**Author:** ![jonathanbruno](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/jonathanbruno/32/1215_2.png) [@jonathanbruno](https://discuss.hotwired.dev/u/jonathanbruno)\
**Post date:** [January 4, 2021, 5:06pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/5 "2021-01-04T17:06:43Z")

</div>

I think only remote invocation wont work, I have a demo that currently works with hotwire+railsujs

---

<div class="post-metadata">

**Author:** ![mrhead](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/mrhead/32/120_2.png) [@mrhead](https://discuss.hotwired.dev/u/mrhead)\
**Post date:** [January 4, 2021, 7:36pm UTC](https://discuss.hotwired.dev/t/link-to-does-not-work-with-delete-method-when-app-is-created-with-skip-javascript/1850/6 "2021-01-04T19:36:58Z")

</div>

My bad! @jonathanbruno is right.

I always used `data-method` with `data-remote` and I thought that the former depends on the latter. However, it is not the case and checking the rails-ujs source code confirms it.
