mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-09 07:28:41 -07:00
working on question_lists
This commit is contained in:
parent
d731049fc6
commit
cc84c3bbda
26 changed files with 498 additions and 10 deletions
26
app/models/question_list.rb
Normal file
26
app/models/question_list.rb
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
class QuestionList < ApplicationRecord
|
||||
|
||||
validates :name, presence: true
|
||||
validates :question_ids, presence: true
|
||||
|
||||
attr_accessor :question_id_array
|
||||
before_validation :convert_question_id_array
|
||||
after_initialize :set_question_id_array
|
||||
|
||||
def questions
|
||||
question_id_array.collect { |id| Question.where(id: id).first }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_question_id_array
|
||||
return if question_id_array.blank?
|
||||
self.question_ids = question_id_array.reject { |id| id.to_s.empty? }.join(',')
|
||||
end
|
||||
|
||||
def set_question_id_array
|
||||
return if question_ids.blank?
|
||||
self.question_id_array = question_ids.split(',').map(&:to_i)
|
||||
end
|
||||
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue