Module: Surveyor::Models::ResponseMethods::ClassMethods

Defined in:
lib/surveyor/models/response_methods.rb

Instance Method Summary collapse

Instance Method Details

#applicable_attributes(attrs) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/surveyor/models/response_methods.rb', line 21

def applicable_attributes(attrs)
  result = HashWithIndifferentAccess.new(attrs)
  answer_id = result[:answer_id].is_a?(Array) ? result[:answer_id].last : result[:answer_id] # checkboxes are arrays / radio buttons are not arrays
  if result[:string_value] && !answer_id.blank? && Answer.exists?(answer_id)
    answer = Answer.find(answer_id)
    result.delete(:string_value) unless answer.response_class && answer.response_class.to_sym == :string
  end
  result
end