adamu

adamu

Programming Phoenix 1.4: Chapter 5 HTTP DELETE clarification (page 98)

I’ve been dabbling in Elixir for years, but I’m finally learning Phoenix properly. Very much enjoying this book and how it explains everything the framework is doing along the way to prove there is no magic.

However, I think I found some magic (or at least, some behaviour that does not follow the explanation) for the link helper.

Quote:

The link:

• Uses the HTTP delete method

By passing the :method option to link, Phoenix generates a form tag instead of an anchor tag. Links without a specified HTTP method will default to GET, and Phoenix will render a simple link.

However, when I inspect the HTML in the browser, it has generated an anchor tag

<a data-csrf="NhNzCRlHNh4vGSxzPjAqKj1EBiZiNXMoig59otnzWXVGFCGsyivk1vEo" data-method="delete" data-to="/sessions/6" href="/sessions/6" rel="nofollow">Log out</a>

When I read this, I expected a <form> tag instead of an <a> tag.

I suppose the anchor tag is a kind of form tag, but it’s not a <form> and the “instead of an anchor tag” is confusing. Maybe it meant instead of an <a href> tag?

When clicked, the request is submitted as form data using post, not delete, contrary to the explanation. Although the delete action on the controller is called, so somewhere something must be interpreting post requests and checking for a _method paramter to route it as if the _method was the HTTP method.

Most Liked

adamu

adamu

Looking into this some more, this is explained in the Endpoint plugs section of the Phoenix Plug Guide:

  • Plug.MethodOverride - converts the request method to PUT, PATCH or DELETE for POST requests with a valid _method parameter

Popular Prag Prog topics Top

johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
New
jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
leba0495
Hello! Thanks for the great book. I was attempting the Trie (chap 17) exercises and for number 4 the solution provided for the autocorre...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New

Other popular topics Top

wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
Exadra37
Oh just spent so much time on this to discover now that RancherOS is in end of life but Rancher is refusing to mark the Github repo as su...
New
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
New

Latest in PragProg

View all threads ❯