title: Ruby on Rails | How to apply validation on rails form
body: <p>I am adding the promo code option for my application. I want to apply validation on the form that will match the entered promo code by the user to the promo code that has been already there in the admin dashboard (Activeadmin is used for admin dashboard).</p>
  <p>I have tried a few options but nothing works. Examples that I have tried -</p>
  <pre><code>def validate_promo_code
    if promo_code.present? and (!promo_code.match(EngineName::PromoCode.promo_code))
      errors.add :promo_code, &quot;must be a valid promo code&quot;
    end
  end
  </code></pre>
  <pre><code>def validate_promo_code
   if promo_code.present? and (promo_code != EngineName::PromoCode.where(promo_code: promo_code))
     errors.add :promo_code, &quot;must be valid promo code&quot;
     return;
   end
  end
  </code></pre>
  <p>Does anyone has any idea how to achieve this? Please Help!</p>