title: Password confirmation in Rails 5
body: <p>This is my view:</p>
  
  <pre><code>&lt;%=form_for [:admin, @user] do |f|%&gt;
  
      &lt;ul&gt;
          &lt;% @user.errors.full_messages.each do |msg| %&gt;
              &lt;li&gt;&lt;%= msg %&gt;&lt;/li&gt;
          &lt;% end %&gt;
      &lt;/ul&gt;
  
      &lt;%=f.label :name %&gt;
      &lt;%=f.text_field :name %&gt;
  
  
      &lt;%=f.label :email %&gt;
      &lt;%=f.text_field :email %&gt;
  
      &lt;%=f.label :password %&gt;
      &lt;%=f.password_field :password %&gt;
  
      &lt;%=f.label :password_confirmation %&gt;
      &lt;%=f.password_field :password_confirmation%&gt;
  
      &lt;%=f.submit "Submit" %&gt;
  &lt;%end%&gt;
  </code></pre>
  
  <p>Controller code for adding user:</p>
  
  <pre><code>def create
      @user = User.new(user_params)
  
      if @user.save
          redirect_to admin_users_path
      else
          render 'new'
      end
  end
  
  private
  def user_params
      params.require(:user).permit(:name, :email, :password)
  end
  </code></pre>
  
  <p>These are validations in the model:</p>
  
  <pre><code>validates :name, presence: true
  validates :email, presence: true
  validates :password, presence: true
  validates :password, confirmation: { case_sensitive: true }
  </code></pre>
  
  <p>But <code>confirmation password</code> doesn't work. </p>
  
  <p>Validation works for all  (they are required) form elements, except second password input - <code>password_confirmation</code> which can be different from first password input. </p>
  
  <p>User is added to the database even if second password input is empty, because in the validation rules, there is no rule for that .</p>
  
  <p>What am I doing wrong ?</p>