Skip to content

Instantly share code, notes, and snippets.

@barek2k2
Created June 29, 2014 16:16
Show Gist options
  • Save barek2k2/00e027cf4b18fa464a66 to your computer and use it in GitHub Desktop.
Save barek2k2/00e027cf4b18fa464a66 to your computer and use it in GitHub Desktop.
question model
class Question < ActiveRecord::Base
scope :start_questions, -> { where(start: true) }
def end_question?
self.next_question_id_for_yes.nil? && self.next_question_id_for_no.nil?
end
def start_question?
self.start?
end
def next_question_for(answer)
next_question_id = self.send("next_question_id_for_#{answer}".to_sym)
Question.find(next_question_id)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment