title: Rails - How to validate a field only if a another field has a certain value?
body: <p>In my form I have a Select with three values: <strong>Apple</strong>, <strong>Banana</strong> and <strong>Cherry</strong>. If I choose <strong>Apple</strong> from the select I hide another Select- and a Text-field with some Javascript, because when <strong>Apple</strong> is chosen, there is no need to fill in these other two fields anymore.</p>
  <p>So now I have a problem with validating my form when it's submitted.
  I've found some similar problems for example in the case of
  &quot;Only validate a field if another is blank.&quot;</p>
  <p>This problem was solved like this:</p>
  <pre><code>validates_presence_of :mobile_number, :unless =&gt; :home_phone?
  </code></pre>
  <p>So I've just tried the first thing which popped into my mind:</p>
  <pre><code>validates_presence_of :state, :granted_at, :if =&gt; :type != 1
  </code></pre>
  <p>But when I run it, I get this error:</p>
  <pre><code>undefined method `validate' for true:TrueClass
  </code></pre>
  <p>How can I conditionally perform a validation on a field based on whether or not another field has a particular value?</p>