Class: Rapidfire::Question
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Rapidfire::Question
- Defined in:
- app/models/rapidfire/question.rb
Direct Known Subclasses
Rapidfire::Questions::Checkbox, Rapidfire::Questions::Date, Rapidfire::Questions::Long, Rapidfire::Questions::Numeric, Rapidfire::Questions::Select, Rapidfire::Questions::Short
Class Method Summary collapse
Instance Method Summary collapse
- #rules ⇒ Object
-
#validate_answer(answer) ⇒ Object
answer will delegate its validation to question, and question will inturn add validations on answer on the fly!.
Class Method Details
.inherited(child) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'app/models/rapidfire/question.rb', line 15 def self.inherited(child) child.instance_eval do def model_name Question.model_name end end super end |
Instance Method Details
#rules ⇒ Object
25 26 27 |
# File 'app/models/rapidfire/question.rb', line 25 def rules validation_rules || {} end |
#validate_answer(answer) ⇒ Object
answer will delegate its validation to question, and question will inturn add validations on answer on the fly!
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/rapidfire/question.rb', line 31 def validate_answer(answer) if rules[:presence] == "1" answer.validates_presence_of :answer_text end if rules[:minimum].present? || rules[:maximum].present? min_max = { minimum: rules[:minimum].to_i } min_max[:maximum] = rules[:maximum].to_i if rules[:maximum].present? answer.validates_length_of :answer_text, min_max end end |