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

kuroneko
Whilst the author has been careful to provide exact results for the tests elsewhere in the book (such as surds with the transformation te...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |&gt; handle_event() |&gt; render() but the correc...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex&gt; product = %Product{} %Pento....
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
New
adamwoolhether
I’m not quite sure what’s going on here, but I’m unable to have to containers successfully complete the Readiness/Liveness checks. I’m im...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
I’ve been hearing quite a lot of comments relating to the sound of a keyboard, with one of the most desirable of these called ‘thock’, he...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
AstonJ
Do the test and post your score :nerd_face: :keyboard: If possible, please add info such as the keyboard you’re using, the layout (Qw...
New
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
PragmaticBookshelf
Author Spotlight James Stanier @jstanier James Stanier, author of Effective Remote Work , discusses how to rethink the office as we e...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New

Latest in PragProg

View all threads ❯