You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sqm-dashboards/app/models/question.rb

22 lines
526 B

class Question < ApplicationRecord
belongs_to :category
validates :text, presence: true
validates :option1, presence: true
validates :option2, presence: true
validates :option3, presence: true
validates :option4, presence: true
validates :option5, presence: true
scope :for_category, -> (category) { where(category: category) }
def options
[option1, option2, option3, option4, option5].map(&:downcase).map(&:strip)
end
def option_index(answer)
options.index(answer.downcase.strip)
end
end