Questions: fixes, redesign form, fix edit error
This commit is contained in:
parent
38bc2e3c3a
commit
e25425bd77
20 changed files with 300 additions and 117 deletions
|
|
@ -173,6 +173,7 @@ class Ability
|
|||
can :manage, Question do |question|
|
||||
!(question.conferences.pluck(:id) & conf_ids_for_info_desk).empty?
|
||||
end
|
||||
can [ :show, :toggle_question ], Question, global: true
|
||||
end
|
||||
|
||||
def signed_in_with_volunteers_coordinator_role(user)
|
||||
|
|
|
|||
|
|
@ -1,8 +1,21 @@
|
|||
class Answer < ActiveRecord::Base
|
||||
attr_accessible :title
|
||||
|
||||
has_many :qanswers
|
||||
has_many :qanswers, dependent: :destroy
|
||||
has_many :questions, through: :qanswers
|
||||
|
||||
validates :title, presence: true
|
||||
validate :no_modification_if_used
|
||||
|
||||
def no_modification_if_used
|
||||
errors.add('', 'cannot be altered or deleted, if they are being used.') if self.title_changed? && self.questions.any?
|
||||
end
|
||||
|
||||
# Gets answer, question, conference
|
||||
## Returns
|
||||
# the amount of replies for a given answer
|
||||
# + integer +
|
||||
def sum_replies question, conference
|
||||
self.qanswers.find_by(question: question).registrations.where(conference: conference).count
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ class Qanswer < ActiveRecord::Base
|
|||
attr_accessible :question_id, :answer_id
|
||||
|
||||
belongs_to :question
|
||||
belongs_to :answer, dependent: :delete
|
||||
belongs_to :answer
|
||||
|
||||
has_and_belongs_to_many :registrations
|
||||
|
||||
|
|
|
|||
|
|
@ -8,12 +8,5 @@ class Question < ActiveRecord::Base
|
|||
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 self.answers.blank?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue