Files
osem/app/models/question.rb
Chaitanya 4427f43bdf Enable Style/RedundantSelf Rubocop cop
This cop checks for redundant uses of self. It supports autocorrection, so all the offenses where automatically solved.

Closes #1373
2017-03-28 13:27:52 +05:30

18 lines
465 B
Ruby

class Question < ActiveRecord::Base
belongs_to :question_type
has_and_belongs_to_many :conferences
has_many :qanswers, dependent: :delete_all
has_many :answers, through: :qanswers, dependent: :delete_all
validates :title, :question_type_id, presence: true
validate :existing_answers
accepts_nested_attributes_for :answers, allow_destroy: true
private
def existing_answers
errors.add(:base, 'Must have answers') if answers.blank?
end
end