diff --git a/app/controllers/admin/poll/answers_controller.rb b/app/controllers/admin/poll/answers_controller.rb
new file mode 100644
index 000000000..f949ad115
--- /dev/null
+++ b/app/controllers/admin/poll/answers_controller.rb
@@ -0,0 +1,29 @@
+class Admin::Poll::AnswersController < Admin::Poll::BaseController
+ before_action :load_question
+
+ load_and_authorize_resource :question, class: "::Poll::Question"
+
+ def new
+ @answer = Poll::QuestionAnswer.new
+ end
+
+ def create
+ @answer = Poll::QuestionAnswer.new(answer_params)
+
+ if @answer.save
+ redirect_to admin_question_path(@question)
+ else
+ render :new
+ end
+ end
+
+ private
+
+ def answer_params
+ params.require(:poll_question_answer).permit(:title, :description, :poll_question_id)
+ end
+
+ def load_question
+ @question = ::Poll::Question.find(params[:question_id])
+ end
+end
diff --git a/app/models/poll/question_answer.rb b/app/models/poll/question_answer.rb
index 508a92ee2..871336cfd 100644
--- a/app/models/poll/question_answer.rb
+++ b/app/models/poll/question_answer.rb
@@ -2,4 +2,8 @@ class Poll::QuestionAnswer < ActiveRecord::Base
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'poll_question_id'
validates :title, presence: true
+
+ def description
+ super.try :html_safe
+ end
end
diff --git a/app/views/admin/poll/answers/_form.html.erb b/app/views/admin/poll/answers/_form.html.erb
new file mode 100644
index 000000000..7da1afd26
--- /dev/null
+++ b/app/views/admin/poll/answers/_form.html.erb
@@ -0,0 +1,24 @@
+<%= form_for(@answer, url: form_url) do |f| %>
+
+ <%= render 'shared/errors', resource: @answer %>
+
+ <%= f.hidden_field :poll_question_id, value: @question.id %>
+
+
+
+ <%= f.text_field :title %>
+
+
+ <%= f.cktext_area :description,
+ maxlength: Poll::Question.description_max_length,
+ ckeditor: { language: I18n.locale } %>
+
+
+
+
+ <%= f.submit(class: "button expanded", value: t("shared.save")) %>
+
+
+
+
+<% end %>
diff --git a/app/views/admin/poll/answers/new.html.erb b/app/views/admin/poll/answers/new.html.erb
new file mode 100644
index 000000000..b4d02cfeb
--- /dev/null
+++ b/app/views/admin/poll/answers/new.html.erb
@@ -0,0 +1,7 @@
+<%= back_link_to %>
+
+<%= t('admin.answers.new.title') %>
+
+
+ <%= render "form", form_url: admin_question_answers_path %>
+
diff --git a/app/views/admin/poll/questions/show.html.erb b/app/views/admin/poll/questions/show.html.erb
index 9d38735ca..6f8dfd583 100644
--- a/app/views/admin/poll/questions/show.html.erb
+++ b/app/views/admin/poll/questions/show.html.erb
@@ -27,7 +27,7 @@
| <%= t('admin.questions.show.valid_answers') %> |
- <%= link_to t("admin.questions.show.add_answer"), "#", class: "button hollow float-right" %> |
+ <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), class: "button hollow float-right" %> |
@@ -36,7 +36,10 @@
-
+ <% @question.question_answers.each do |answer| %>
+ | <%= answer.title %> |
+ <%= answer.description %> |
+ <% end %>
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml
index 1e3f62b1a..dd279f6ae 100644
--- a/config/locales/en/activerecord.yml
+++ b/config/locales/en/activerecord.yml
@@ -211,6 +211,9 @@ en:
image:
title: Title
attachment: Attachment
+ poll/question_answer:
+ title: "Answer"
+ description: "Description"
errors:
models:
user:
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 2b8a18ce2..2c6b8bc97 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -608,6 +608,9 @@ en:
video_url: External video
documents: Documents (1)
preview: View on website
+ answers:
+ new:
+ title: "New answer"
recounts:
index:
title: "Recounts"
diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml
index 108f19fcf..c12b8e9a9 100644
--- a/config/locales/es/activerecord.yml
+++ b/config/locales/es/activerecord.yml
@@ -205,6 +205,9 @@ es:
image:
title: Título
attachment: Archivo adjunto
+ poll/question_answer:
+ title: "Respuesta"
+ description: "Descripción"
errors:
models:
user:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 333cf9cf9..37e34fa52 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -608,6 +608,9 @@ es:
video_url: Video externo
documents: Documentos (1)
preview: Ver en la web
+ answers:
+ new:
+ title: "Nueva respuesta"
recounts:
index:
title: "Recuentos"
diff --git a/config/locales/fr/activerecord.yml b/config/locales/fr/activerecord.yml
index b588d37dc..d6ab5db80 100644
--- a/config/locales/fr/activerecord.yml
+++ b/config/locales/fr/activerecord.yml
@@ -147,6 +147,9 @@ fr:
name: Nom
locale: Langue
body: Contenu
+ poll/question_answer:
+ title: "Réponse"
+ description: "Description"
errors:
models:
user:
diff --git a/config/locales/fr/admin.yml b/config/locales/fr/admin.yml
index f509b2a94..e000c8a28 100644
--- a/config/locales/fr/admin.yml
+++ b/config/locales/fr/admin.yml
@@ -386,6 +386,9 @@ fr:
answer: "Réponse"
description: Description
preview: Voir l'aperçu
+ answers:
+ new:
+ title: "Nouvelle réponse"
recounts:
index:
title: "Dépouillements"
diff --git a/config/routes.rb b/config/routes.rb
index 410f2dced..d72058737 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -302,7 +302,9 @@ Rails.application.routes.draw do
end
end
- resources :questions
+ resources :questions do
+ resources :answers, only: [:new, :create]
+ end
end
resources :verifications, controller: :verifications, only: :index do