@@ -1,5 +1,6 @@
|
|||||||
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
||||||
before_action :load_question
|
before_action :load_question, except: [:show, :edit, :update]
|
||||||
|
before_action :load_answer, only: [:show, :edit, :update]
|
||||||
|
|
||||||
load_and_authorize_resource :question, class: "::Poll::Question"
|
load_and_authorize_resource :question, class: "::Poll::Question"
|
||||||
|
|
||||||
@@ -18,6 +19,21 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @answer.update(answer_params)
|
||||||
|
redirect_to admin_answer_path(@answer),
|
||||||
|
notice: t("flash.actions.save_changes.notice")
|
||||||
|
else
|
||||||
|
render :edit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def answer_params
|
def answer_params
|
||||||
@@ -27,4 +43,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
|
|||||||
def load_question
|
def load_question
|
||||||
@question = ::Poll::Question.find(params[:question_id])
|
@question = ::Poll::Question.find(params[:question_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_answer
|
||||||
|
@answer = ::Poll::Question::Answer.find(params[:id])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,17 +2,14 @@
|
|||||||
|
|
||||||
<%= render 'shared/errors', resource: @answer %>
|
<%= render 'shared/errors', resource: @answer %>
|
||||||
|
|
||||||
<%= f.hidden_field :question_id, value: @question.id %>
|
<%= f.hidden_field :question_id, value: @answer.question_id || @question.id %>
|
||||||
|
|
||||||
<%= f.label :title, t('admin.questions.new.form.title') %>
|
<%= f.text_field :title %>
|
||||||
<%= f.text_field :title, label: false %>
|
|
||||||
|
|
||||||
<div class="ckeditor">
|
<div class="ckeditor">
|
||||||
<%= f.label :description, t('admin.questions.new.form.description') %>
|
|
||||||
<%= f.cktext_area :description,
|
<%= f.cktext_area :description,
|
||||||
maxlength: Poll::Question.description_max_length,
|
maxlength: Poll::Question.description_max_length,
|
||||||
ckeditor: { language: I18n.locale },
|
ckeditor: { language: I18n.locale } %>
|
||||||
label: false %>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="small-12 medium-6 large-4">
|
<div class="small-12 medium-6 large-4">
|
||||||
|
|||||||
14
app/views/admin/poll/questions/answers/edit.html.erb
Normal file
14
app/views/admin/poll/questions/answers/edit.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
|
||||||
|
<ul class="breadcrumbs margin-top">
|
||||||
|
<li><%= @answer.title %></li>
|
||||||
|
<li><%= t('admin.answers.edit.title') %></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h2 class="margin-top">
|
||||||
|
<%= t("admin.answers.edit.title") %>
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<div class="poll-question-answer-form">
|
||||||
|
<%= render "form", form_url: admin_answer_path(@answer) %>
|
||||||
|
</div>
|
||||||
32
app/views/admin/poll/questions/answers/show.html.erb
Normal file
32
app/views/admin/poll/questions/answers/show.html.erb
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<%= back_link_to %>
|
||||||
|
|
||||||
|
<%= link_to t('shared.edit'), edit_admin_answer_path(@answer),
|
||||||
|
class: "button hollow float-right" %>
|
||||||
|
|
||||||
|
<ul class="breadcrumbs margin-top">
|
||||||
|
<li><%= @answer.question.title %></li>
|
||||||
|
<li><%= @answer.title %></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div class="clear"></div>
|
||||||
|
|
||||||
|
<div class="small-12 medium-6">
|
||||||
|
<div class="callout highlight">
|
||||||
|
<p>
|
||||||
|
<strong><%= t("admin.answers.show.title") %></strong>
|
||||||
|
<br>
|
||||||
|
<%= @answer.title %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong><%= t("admin.answers.show.description") %></strong>
|
||||||
|
<%= @answer.description %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong><%= t("admin.answers.show.images") %></strong>
|
||||||
|
<br>
|
||||||
|
<%= link_to t("admin.answers.show.images_list"), admin_answer_images_path(@answer) %>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
<table class="margin-top">
|
<table class="margin-top">
|
||||||
<tr>
|
<tr>
|
||||||
<th colspan="3" scope="col" class="with-button">
|
<th colspan="3" class="with-button">
|
||||||
<%= t('admin.questions.show.valid_answers') %>
|
<%= t('admin.questions.show.valid_answers') %>
|
||||||
<%= link_to t("admin.questions.show.add_answer"),
|
<%= link_to t("admin.questions.show.add_answer"),
|
||||||
new_admin_question_answer_path(@question),
|
new_admin_question_answer_path(@question),
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
<% @question.question_answers.each do |answer| %>
|
<% @question.question_answers.each do |answer| %>
|
||||||
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
<tr id="<%= dom_id(answer) %>" class="poll_question_answer">
|
||||||
<td><%= answer.title %></td>
|
<td><%= link_to answer.title, admin_answer_path(answer) %></td>
|
||||||
<td><%= answer.description %></td>
|
<td><%= answer.description %></td>
|
||||||
<td class="text-center">
|
<td class="text-center">
|
||||||
(<%= answer.images.count %>)<br>
|
(<%= answer.images.count %>)<br>
|
||||||
|
|||||||
@@ -213,9 +213,9 @@ en:
|
|||||||
image:
|
image:
|
||||||
title: Title
|
title: Title
|
||||||
attachment: Attachment
|
attachment: Attachment
|
||||||
poll/question_answer:
|
poll/question/answer:
|
||||||
title: "Answer"
|
title: Answer
|
||||||
description: "Description"
|
description: Description
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -609,7 +609,14 @@ en:
|
|||||||
images_list: Images list
|
images_list: Images list
|
||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: "New answer"
|
title: New answer
|
||||||
|
show:
|
||||||
|
title: Title
|
||||||
|
description: Description
|
||||||
|
images: Images
|
||||||
|
images_list: Images list
|
||||||
|
edit:
|
||||||
|
title: Edit answer
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Recounts"
|
title: "Recounts"
|
||||||
|
|||||||
@@ -207,9 +207,9 @@ es:
|
|||||||
image:
|
image:
|
||||||
title: Título
|
title: Título
|
||||||
attachment: Archivo adjunto
|
attachment: Archivo adjunto
|
||||||
poll/question_answer:
|
poll/question/answer:
|
||||||
title: "Respuesta"
|
title: Respuesta
|
||||||
description: "Descripción"
|
description: Descripción
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -611,9 +611,16 @@ es:
|
|||||||
images_list: Lista de imágenes
|
images_list: Lista de imágenes
|
||||||
answers:
|
answers:
|
||||||
new:
|
new:
|
||||||
title: "Nueva respuesta"
|
title: Nueva respuesta
|
||||||
video_url: Video externo
|
video_url: Video externo
|
||||||
documents: Documentos (1)
|
documents: Documentos (1)
|
||||||
|
show:
|
||||||
|
title: Título
|
||||||
|
description: Descripción
|
||||||
|
images: Imágenes
|
||||||
|
images_list: Lista de imágenes
|
||||||
|
edit:
|
||||||
|
title: Editar respuesta
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Recuentos"
|
title: "Recuentos"
|
||||||
|
|||||||
@@ -147,9 +147,9 @@ fr:
|
|||||||
name: Nom
|
name: Nom
|
||||||
locale: Langue
|
locale: Langue
|
||||||
body: Contenu
|
body: Contenu
|
||||||
poll/question_answer:
|
poll/question/answer:
|
||||||
title: "Réponse"
|
title: Réponse
|
||||||
description: "Description"
|
description: Description
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
user:
|
user:
|
||||||
|
|||||||
@@ -387,8 +387,15 @@ fr:
|
|||||||
description: Description
|
description: Description
|
||||||
preview: Voir l'aperçu
|
preview: Voir l'aperçu
|
||||||
answers:
|
answers:
|
||||||
|
show:
|
||||||
|
title: Titre
|
||||||
|
description: Description
|
||||||
|
images: Images
|
||||||
|
images_list: Liste des images
|
||||||
new:
|
new:
|
||||||
title: "Nouvelle réponse"
|
title: Nouvelle réponse
|
||||||
|
edit:
|
||||||
|
title: Modifier réponse
|
||||||
recounts:
|
recounts:
|
||||||
index:
|
index:
|
||||||
title: "Dépouillements"
|
title: "Dépouillements"
|
||||||
|
|||||||
@@ -301,7 +301,7 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
|
|
||||||
resources :questions do
|
resources :questions do
|
||||||
resources :answers, only: [:new, :create], controller: 'questions/answers', shallow: true do
|
resources :answers, except: [:index, :destroy, :delete], controller: 'questions/answers', shallow: true do
|
||||||
resources :images, controller: 'questions/answers/images'
|
resources :images, controller: 'questions/answers/images'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
51
spec/features/admin/poll/questions/answers/answers_spec.rb
Normal file
51
spec/features/admin/poll/questions/answers/answers_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
feature 'Answers' do
|
||||||
|
|
||||||
|
background do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as (admin.user)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Create' do
|
||||||
|
question = create(:poll_question)
|
||||||
|
title = 'Whatever the question may be, the answer is always 42'
|
||||||
|
description = "The Hitchhiker's Guide To The Universe"
|
||||||
|
|
||||||
|
visit admin_question_path(question)
|
||||||
|
click_link 'Add answer'
|
||||||
|
|
||||||
|
fill_in 'poll_question_answer_title', with: title
|
||||||
|
fill_in 'poll_question_answer_description', with: description
|
||||||
|
|
||||||
|
click_button 'Save'
|
||||||
|
|
||||||
|
expect(page).to have_content(title)
|
||||||
|
expect(page).to have_content(description)
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'Update' do
|
||||||
|
question = create(:poll_question)
|
||||||
|
answer = create(:poll_question_answer, question: question)
|
||||||
|
|
||||||
|
visit admin_answer_path(answer)
|
||||||
|
|
||||||
|
click_link 'Edit'
|
||||||
|
|
||||||
|
old_title = answer.title
|
||||||
|
new_title = 'Ex Machina'
|
||||||
|
|
||||||
|
fill_in 'poll_question_answer_title', with: new_title
|
||||||
|
|
||||||
|
click_button 'Save'
|
||||||
|
|
||||||
|
expect(page).to have_content('Changes saved')
|
||||||
|
expect(page).to have_content(new_title)
|
||||||
|
|
||||||
|
visit admin_question_path(question)
|
||||||
|
|
||||||
|
expect(page).to have_content(new_title)
|
||||||
|
expect(page).to_not have_content(old_title)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user