Rails - Confirmation Fields Are Tied to HTML Form Helpers
<p>Rails only checks for field confirmations if there is a corresponding <code>_confirmation</code> field in the request.</p>

<p>To explain it further, here is a sample Rails view:</p>

<pre><code>&lt;%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %&gt;

  &lt;%= f.label :email %&gt;
  &lt;%= f.email_field :email, autofocus: true %&gt;

  &lt;%= f.label :password %&gt;
  &lt;%= f.password_field :password, autocomplete: "off" %&gt;

  &lt;%= f.label :password_confirmation %&gt;
  &lt;%= f.password_field :password_confirmation, autocomplete: "off" %&gt;

  &lt;%= f.submit "Sign up" %&gt;

&lt;% end %&gt;
</code></pre>

<p>This form works as expected.</p>

<p>However, if you remove:</p>

<pre><code>&lt;%= f.label :password_confirmation %&gt;
&lt;%= f.password_field :password_confirmation, autocomplete: "off" %&gt;
</code></pre>

<p>Passwords are no longer confirmed.</p>

<p>The problem I am having is all my <code>JSON</code> requests are going through successfully without a corresponding <code>_confirmation</code> field.</p>

<p>This request is successful:</p>

<pre><code>{
    "email": "me@example.com",
    "password" : "somepassword"
}
</code></pre>

<p>This is not:</p>

<pre><code>{
    "email": "me@example.com",
    "password" : "somepassword",
    "password_confirmation": "_somepassword 
}
</code></pre>

<p>Also, for the second JSON, if <code>password</code> and <code>password_confirmation</code> match then the request is successful(which is understood).</p>

<p>I think the first request should not be successful since there is no password confirmation.</p>

<p>Is this a bug or an expected behaviour since confirmation fields should be tied to ActiveRecord and not HTML from helpers.</p>

<p>How will one replicate field confirmations in Rails based JSON APIs then?</p>