title: How can I validate only specific fields when doing update_attributes in Rails?
body: <p>I have a <code>User</code> model, where are following validations</p>
  
  <pre><code>validates :username, :presence =&gt; true, :uniqueness =&gt; true
  validates :email, :presence =&gt; true, :uniqueness =&gt; true
  validates :password, :confirmation =&gt; true
  validates_presence_of :password, :on =&gt; :create
  
  validates_presence_of :bnet_username, :on =&gt; :update
  validates_presence_of :bnet_code, :on =&gt; :update
  </code></pre>
  
  <p>The reason why <code>bnet_username</code> and <code>bnet_code</code> is only on update is because I already had existing users when I added those fields and they're not in the registration form, so I only need users to set them once they're registered on the website.</p>
  
  <p>There is one problem though, and that is when a user without set <code>bnet_username</code> and <code>bnet_code</code> tries to reset his password. In that case, the <code>PasswordResetController</code> will try to update his attributes, but the validation will fail.</p>
  
  <pre><code>if @user.update_attributes(params[:user])
    redirect_to root_url, :notice =&gt; "Password has been reset! You can now log in."
  ...
  </code></pre>
  
  <p>The problem is, I need to validate password when user tries to reset it, but I don't want to validate it when he's just updating his profile.</p>
  
  <p>I also can't skip the validation all together on the password reset, because I need to validate the password itself.</p>
  
  <p><strong>Is there any simple solution on how to say which just which validations I need to run? Or am I approaching this completely wrong?</strong></p>
  
  <p><strong>edit</strong>: Basically there is one case when this causes problems. Existing user who didn't yet set his <code>bnet_username</code> and <code>bnet_code</code>, but he wants to change his password.</p>
  
  <p>Since change of password is an update action, it will trigger validations for <code>bnet_username</code> and <code>bnet_password</code>. But I need them to be set on update only, because I want users to set them when they edit their profile.</p>
  
  <p>It's not a mandatory field when user is registering, but they have to set it when they try to update profile information.</p>