Add given_order to related poll question answers forms

Since given order is no longer being generated automatically we need
to add it to related forms and to strong parameters methods
This commit is contained in:
Senén Rodero Rodríguez
2018-12-27 18:13:32 +01:00
parent c73aae9663
commit 9d9ad5003b
5 changed files with 10 additions and 4 deletions

View File

@@ -50,7 +50,8 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController
def answer_params
documents_attributes = [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]
attributes = [:title, :description, :question_id, documents_attributes: documents_attributes]
attributes = [:title, :description, :given_order, :question_id,
documents_attributes: documents_attributes]
params.require(:poll_question_answer).permit(*attributes, *translation_params(Poll::Question::Answer))
end

View File

@@ -62,7 +62,8 @@ class Dashboard::PollsController < Dashboard::BaseController
end
def question_answers_attributes
[:id, :_destroy, :title, :description, :question_id, documents_attributes: documents_attributes]
[:id, :_destroy, :title, :description, :given_order, :question_id,
documents_attributes: documents_attributes]
end
def documents_attributes

View File

@@ -4,6 +4,9 @@
<%= render 'shared/errors', resource: @answer %>
<%= f.hidden_field :given_order,
value: @answer.persisted? ? @answer.given_order : @answer.class.last_position(@answer.question_id || @question.id) + 1 %>
<%= f.hidden_field :question_id, value: @answer.question_id || @question.id %>
<%= f.translatable_text_field :title %>

View File

@@ -1,5 +1,6 @@
<div class="small-12 medium-6 column">
<div class="answer-fields">
<%= f.hidden_field :given_order %>
<div class="row expanded">
<div class="small-12 medium-9 column">
<%= f.text_field :title %>

View File

@@ -65,7 +65,7 @@ feature 'Answers' do
expect(page).to have_content(new_title)
expect(page).not_to have_content(old_title)
expect(page.body.index(new_title)).to be < page.body.index(answer2.title)
expect(answer2.title).to appear_before(new_title)
end
end