0

I have a Survey model that has_many Questions. I want some questions only to require an answer if another Question is answered.

For example, If a question one question may be "Did you use the lesson plan for this week's lesson?", and and another may be "What week of the lesson plan did you use?", but it's clear that the latter would only be required to be filled out if the answer to the first one is "Yes." How can I make the validation of one Question conditional on the response to another Question?

My question is different from the one previously asked because it's conditional validation based on the fields of another instance of the model, not based on the model's own fields

Ben Muschol
  • 608
  • 1
  • 5
  • 21
  • 1
    Possible duplicate of [Rails - How to validate a field only if a another field has a certain value?](http://stackoverflow.com/questions/8848601/rails-how-to-validate-a-field-only-if-a-another-field-has-a-certain-value) – Antarr Byrd Oct 26 '15 at 19:37
  • Don't think so, since my issue isn't validating based on another field of the same model – Ben Muschol Oct 26 '15 at 19:44
  • Is the (other) Question object already answered? If so then, it's accessible from your database, is it not? Or did you mean that it is submitted as a collection of Questions? Perhaps you could supply some code, so we can see the context? – Bryan Oemar Oct 26 '15 at 20:26
  • I haven't written much of the code yet, I'm trying to figure out what approach to use. The idea I have right now is that all of the questions are being submitted in the same (nested) Survey form, so I don't think the other one would be saved to the database yet – Ben Muschol Oct 26 '15 at 20:28

0 Answers0