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

Where Next?

Popular Pragmatic Bookshelf topics Top

yulkin
your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ isn’t...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
raul
Hi Travis! Thank you for the cool book! :slight_smile: I made a list of issues and thought I could post them chapter by chapter. I’m rev...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
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
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
kolossal
Hi, I need some help, I’m new to rust and was learning through your book. but I got stuck at the last stage of distribution. Whenever I t...
New
Henrai
Hi, I’m working on the Chapter 8 of the book. After I add add the point_offset, I’m still able to see acne: In the image above, I re...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
malloryerik
Any thoughts on Svelte? Svelte is a radical new approach to building user interfaces. Whereas traditional frameworks like React and Vue...
New
ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
New
New
PragmaticBookshelf
Learn different ways of writing concurrent code in Elixir and increase your application's performance, without sacrificing scalability or...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1139 25582 756
New
New

Sub Categories: