Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to handle UX confusion caused by an invalid PUT/POST in REST?
    primarykey
    data
    text
    <p><strong><em>My stack is Rails but the problem is actually framework independent</em></strong></p> <p><strong>REST methodology says that</strong></p> <p>In order to see an editing form for existing user:</p> <pre><code>GET: users/:id/edit </code></pre> <p>In order to update the existing user:</p> <pre><code>PUT: users/:id </code></pre> <p><strong>What this means for validation errors</strong></p> <p>This is all sensible except when the form fails to validate. When the form doesn't validate the URL you end up on is not the <code>users/:id/edit</code> URL but instead:</p> <pre><code>users/:id </code></pre> <p>This causes two problems. One is navigation and the other is what happens if the user refreshes the form:</p> <p><strong>A fresh editing form:</strong></p> <p><img src="https://i.stack.imgur.com/CF7vS.png" alt="enter image description here"></p> <p><strong>Same form with errors - although URL and nav suggest we're somewhere different</strong></p> <p><img src="https://i.stack.imgur.com/WfOqx.png" alt="enter image description here"></p> <p>Visually the page is now confusing as the nav and URL suggest that the user is not on the editing form but instead on the <code>resource#show</code> page.</p> <p><strong>What the user sees if they now refresh the form - a completely different page</strong></p> <p>It also has other implications. If the user is frustrated and just wants to reset the form their instinct will be to refresh the page. If they do that though they'll find themself on the <code>resource#show</code> page and not the <code>resource#edit</code> page.</p> <p><img src="https://i.stack.imgur.com/jpZSP.png" alt="enter image description here"></p> <p>Naively we might redirect an invalid submission back to the <code>resource#edit</code> URL. If we do this though we won't (by default in Rails) be able to show them the errors in the form they just submitted as these are stored in memory.</p> <p><strong>Possible solutions</strong></p> <p>As far as I can see there are two ways of solving this:</p> <ol> <li>When <code>PUT users/:id</code> fails to validate: serialize the <code>user</code> object and store it in the session. Redirect to <code>GET users/:id/edit</code> and then unserialize the object on the next page to display the errors - <em>feels messy</em></li> <li>Change routing such that the <code>PUT</code> goes to <code>users/:id/edit</code> rather than <code>users/:id</code> - <em>also feels messy</em>.</li> </ol> <p><strong>The Question</strong></p> <p>What is the most appropriate way to solve this problem? I feel like the serialization approach probably makes the most sense but since it's not a part of Rails core I feel like I'm missing something. I know I'm not the first person to tackle this and am interested in others' approaches</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload