Create 'poll_question_answers' controller and views
This commit is contained in:
29
app/controllers/admin/poll/answers_controller.rb
Normal file
29
app/controllers/admin/poll/answers_controller.rb
Normal file
@@ -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
|
||||
@@ -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
|
||||
|
||||
24
app/views/admin/poll/answers/_form.html.erb
Normal file
24
app/views/admin/poll/answers/_form.html.erb
Normal file
@@ -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 %>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 column">
|
||||
<%= f.text_field :title %>
|
||||
|
||||
<div class="ckeditor">
|
||||
<%= f.cktext_area :description,
|
||||
maxlength: Poll::Question.description_max_length,
|
||||
ckeditor: { language: I18n.locale } %>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="actions small-12 medium-4 column margin-top">
|
||||
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
7
app/views/admin/poll/answers/new.html.erb
Normal file
7
app/views/admin/poll/answers/new.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<%= back_link_to %>
|
||||
|
||||
<h2><%= t('admin.answers.new.title') %></h2>
|
||||
|
||||
<div class="poll-question-answer-form">
|
||||
<%= render "form", form_url: admin_question_answers_path %>
|
||||
</div>
|
||||
@@ -27,7 +27,7 @@
|
||||
<table>
|
||||
<tr>
|
||||
<th colspan="1" scope="colgroup"><%= t('admin.questions.show.valid_answers') %></th>
|
||||
<th colspan="1" scope="colgroup"><%= link_to t("admin.questions.show.add_answer"), "#", class: "button hollow float-right" %></th>
|
||||
<th colspan="1" scope="colgroup"><%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), class: "button hollow float-right" %></th>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
@@ -36,7 +36,10 @@
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
|
||||
<% @question.question_answers.each do |answer| %>
|
||||
<th scope="col"><%= answer.title %></th>
|
||||
<th scope="col"><%= answer.description %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
||||
@@ -211,6 +211,9 @@ en:
|
||||
image:
|
||||
title: Title
|
||||
attachment: Attachment
|
||||
poll/question_answer:
|
||||
title: "Answer"
|
||||
description: "Description"
|
||||
errors:
|
||||
models:
|
||||
user:
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -205,6 +205,9 @@ es:
|
||||
image:
|
||||
title: Título
|
||||
attachment: Archivo adjunto
|
||||
poll/question_answer:
|
||||
title: "Respuesta"
|
||||
description: "Descripción"
|
||||
errors:
|
||||
models:
|
||||
user:
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -147,6 +147,9 @@ fr:
|
||||
name: Nom
|
||||
locale: Langue
|
||||
body: Contenu
|
||||
poll/question_answer:
|
||||
title: "Réponse"
|
||||
description: "Description"
|
||||
errors:
|
||||
models:
|
||||
user:
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user