Create 'poll_question_answers' controller and views

This commit is contained in:
Angel Perez
2017-10-03 23:23:50 -04:00
parent 1d1b861ddf
commit 1cc0816dcd
12 changed files with 90 additions and 3 deletions

View 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

View File

@@ -2,4 +2,8 @@ class Poll::QuestionAnswer < ActiveRecord::Base
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'poll_question_id' belongs_to :question, class_name: 'Poll::Question', foreign_key: 'poll_question_id'
validates :title, presence: true validates :title, presence: true
def description
super.try :html_safe
end
end end

View 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 %>

View 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>

View File

@@ -27,7 +27,7 @@
<table> <table>
<tr> <tr>
<th colspan="1" scope="colgroup"><%= t('admin.questions.show.valid_answers') %></th> <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>
<tr> <tr>
@@ -36,7 +36,10 @@
</tr> </tr>
<tr> <tr>
<% @question.question_answers.each do |answer| %>
<th scope="col"><%= answer.title %></th>
<th scope="col"><%= answer.description %></th>
<% end %>
</tr> </tr>
</table> </table>

View File

@@ -211,6 +211,9 @@ en:
image: image:
title: Title title: Title
attachment: Attachment attachment: Attachment
poll/question_answer:
title: "Answer"
description: "Description"
errors: errors:
models: models:
user: user:

View File

@@ -608,6 +608,9 @@ en:
video_url: External video video_url: External video
documents: Documents (1) documents: Documents (1)
preview: View on website preview: View on website
answers:
new:
title: "New answer"
recounts: recounts:
index: index:
title: "Recounts" title: "Recounts"

View File

@@ -205,6 +205,9 @@ es:
image: image:
title: Título title: Título
attachment: Archivo adjunto attachment: Archivo adjunto
poll/question_answer:
title: "Respuesta"
description: "Descripción"
errors: errors:
models: models:
user: user:

View File

@@ -608,6 +608,9 @@ es:
video_url: Video externo video_url: Video externo
documents: Documentos (1) documents: Documentos (1)
preview: Ver en la web preview: Ver en la web
answers:
new:
title: "Nueva respuesta"
recounts: recounts:
index: index:
title: "Recuentos" title: "Recuentos"

View File

@@ -147,6 +147,9 @@ fr:
name: Nom name: Nom
locale: Langue locale: Langue
body: Contenu body: Contenu
poll/question_answer:
title: "Réponse"
description: "Description"
errors: errors:
models: models:
user: user:

View File

@@ -386,6 +386,9 @@ fr:
answer: "Réponse" answer: "Réponse"
description: Description description: Description
preview: Voir l'aperçu preview: Voir l'aperçu
answers:
new:
title: "Nouvelle réponse"
recounts: recounts:
index: index:
title: "Dépouillements" title: "Dépouillements"

View File

@@ -302,7 +302,9 @@ Rails.application.routes.draw do
end end
end end
resources :questions resources :questions do
resources :answers, only: [:new, :create]
end
end end
resources :verifications, controller: :verifications, only: :index do resources :verifications, controller: :verifications, only: :index do