title: Rails 3: creating a validation with :if statement
body: <p>Hi I'm trying to setup a validation that is only called in a specific form view, to do this I'm trying to create a hidden_field  for a virtual attribute on the form and set this to a value, then validate :if the virtual attribute equals the value.</p>
  
  <p>So far I have:</p>
  
  <pre><code>## user model 
  
  validates_presence_of :password_confirmation, :if =&gt; :confirmation_validation 
  
  attr_accessible :email, :password, :password_confirmation, 
   :remember_me, :name, :avatar, :username, :bio, :confirmation_validation
  
  def confirmation_validation
   # not sure what goes here???
  end
  
  
  ## form view
  
  
  &lt;%= form_for(resource, :validate =&gt; true, :as =&gt; resource_name, :url =&gt; registration_path(resource_name), :html =&gt; { :method =&gt; :put }, :html =&gt; {:multipart =&gt; true}) do |f| %&gt;
  &lt;%= devise_error_messages! %&gt;
  
  &lt;p&gt;&lt;%= f.label :password %&gt; &lt;i&gt;(leave blank if you don't want to change it)&lt;/i&gt;&lt;br /&gt;
  &lt;%= f.password_field :password %&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
  &lt;%= f.password_field :password_confirmation %&gt;
  &lt;% f.hidden_field :confirmation_validation, :value =&gt; 100%&gt;&lt;/p&gt;
  
  &lt;p&gt;&lt;%= f.submit "Update" %&gt;&lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>