diff --git a/app/controllers/admin/questions_controller.rb b/app/controllers/admin/questions_controller.rb index f001155e..c065c334 100644 --- a/app/controllers/admin/questions_controller.rb +++ b/app/controllers/admin/questions_controller.rb @@ -20,6 +20,10 @@ module Admin @question.conference_id = @conference.id authorize! :create, @question + if @question.question_type_id == QuestionType.find_by(title: 'Yes/No').id + @question.answers = [Answer.find_by(title: 'Yes'), Answer.find_by(title: 'No')] + end + respond_to do |format| if @conference.save format.html { redirect_to admin_conference_questions_path, notice: 'Question was successfully created.' } diff --git a/app/views/admin/questions/_form.html.haml b/app/views/admin/questions/_form.html.haml index 1c24e5b4..abefd902 100644 --- a/app/views/admin/questions/_form.html.haml +++ b/app/views/admin/questions/_form.html.haml @@ -5,6 +5,18 @@ = f.input :question_type = f.input :global, label: 'Make Global', hint: '(Global questions are available for selection to all conferences)' - .col-md-6 + .col-md-6.hidden{id: 'answers_col'} = dynamic_association :answers, 'Answers', f, hint: 'Insert your answers in the order you want them to appear' + +:javascript + $("#question_question_type_id").change(function () { + + var selected_type = $(this).find('option:selected').text(); + + if (selected_type == 'Yes/No') + $('#answers_col').addClass('hidden'); + else + $('#answers_col').removeClass('hidden'); + end + });