diff --git a/app/controllers/admin/poll/questions/answers/images_controller.rb b/app/controllers/admin/poll/questions/answers/images_controller.rb index 4074eb371..1bf30907d 100644 --- a/app/controllers/admin/poll/questions/answers/images_controller.rb +++ b/app/controllers/admin/poll/questions/answers/images_controller.rb @@ -23,7 +23,8 @@ class Admin::Poll::Questions::Answers::ImagesController < Admin::Poll::BaseContr private def images_params - params.permit(images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) + params.require(:poll_question_answer).permit(:answer_id, + images_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def load_answer diff --git a/app/controllers/admin/poll/questions/answers_controller.rb b/app/controllers/admin/poll/questions/answers_controller.rb index 4d70b34d1..16867398e 100644 --- a/app/controllers/admin/poll/questions/answers_controller.rb +++ b/app/controllers/admin/poll/questions/answers_controller.rb @@ -1,6 +1,6 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController before_action :load_question, except: [:show, :edit, :update] - before_action :load_answer, only: [:show, :edit, :update] + before_action :load_answer, only: [:show, :edit, :update, :documents] load_and_authorize_resource :question, class: "::Poll::Question" @@ -30,21 +30,24 @@ class Admin::Poll::Questions::AnswersController < Admin::Poll::BaseController redirect_to admin_answer_path(@answer), notice: t("flash.actions.save_changes.notice") else - render :edit + redirect_to :back end end + def documents + @documents = @answer.documents + + render 'admin/poll/questions/answers/documents' + end + private def answer_params - params.require(:poll_question_answer).permit(:title, :description, :question_id) - end - - def load_question - @question = ::Poll::Question.find(params[:question_id]) + params.require(:poll_question_answer).permit(:title, :description, :question_id, documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy]) end def load_answer - @answer = ::Poll::Question::Answer.find(params[:id]) + @answer = ::Poll::Question::Answer.find(params[:id] || params[:answer_id]) end + end diff --git a/app/models/direct_upload.rb b/app/models/direct_upload.rb index 192f06d04..e597f9f12 100644 --- a/app/models/direct_upload.rb +++ b/app/models/direct_upload.rb @@ -19,7 +19,9 @@ class DirectUpload if @resource_type.present? && @resource_relation.present? && (@attachment.present? || @cached_attachment.present?) @resource = @resource_type.constantize.find_or_initialize_by(id: @resource_id) - if @resource.respond_to?(:images) + #Refactor + if @resource.respond_to?(:images) && + ((@attachment.present? && !@attachment.content_type.match(/pdf/)) || @cached_attachment.present?) @relation = @resource.images.send("build", relation_attributtes) elsif @resource.class.reflections[@resource_relation].macro == :has_one @relation = @resource.send("build_#{resource_relation}", relation_attributtes) diff --git a/app/models/poll/question/answer.rb b/app/models/poll/question/answer.rb index fb32de9fc..b3324e57f 100644 --- a/app/models/poll/question/answer.rb +++ b/app/models/poll/question/answer.rb @@ -1,5 +1,10 @@ class Poll::Question::Answer < ActiveRecord::Base include Galleryable + include Documentable + documentable max_documents_allowed: 3, + max_file_size: 3.megabytes, + accepted_content_types: [ "application/pdf" ] + accepts_nested_attributes_for :documents, allow_destroy: true belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id' has_many :videos, class_name: 'Poll::Question::Answer::Video' diff --git a/app/views/admin/_menu.html.erb b/app/views/admin/_menu.html.erb index 81e1ae9bd..21dc7cffb 100644 --- a/app/views/admin/_menu.html.erb +++ b/app/views/admin/_menu.html.erb @@ -53,7 +53,6 @@ <% end %> - <% if feature?(:polls) %>
| <%= t("admin.questions.show.answers.document_title") %> | +<%= t("admin.questions.show.answers.document_actions") %> | +
|---|---|
| + <%= link_to document.title, document.attachment.url %> + | ++ <%= link_to t('documents.buttons.download_document'), + document.attachment.url, + target: "_blank", + rel: "nofollow", + class: 'button hollow' %> + | +
| + | <%= t('admin.questions.show.valid_answers') %> <%= link_to t("admin.questions.show.add_answer"), new_admin_question_answer_path(@question), @@ -41,9 +41,10 @@ | ||||||
|---|---|---|---|---|---|---|---|
| <%= t("admin.questions.show.answers.title") %> | -<%= t("admin.questions.show.answers.description") %> | -<%= t("admin.questions.show.answers.images") %> | -<%= t("admin.questions.show.answers.videos") %> | +<%= t("admin.questions.show.answers.description") %> | +<%= t("admin.questions.show.answers.images") %> | +<%= t("admin.questions.show.answers.documents") %> | +<%= t("admin.questions.show.answers.videos") %> | <%= link_to answer.title, admin_answer_path(answer) %> | <%= answer.description %> |
- (<%= answer.images.count %>) + (<%= answer.images.count %>) + <%= link_to t("admin.questions.show.answers.images_list"), - admin_answer_images_path(answer) %> |
- <%= link_to t("admin.questions.show.answers.video_list", - count: answer.videos.count), - admin_answer_videos_path(answer) %> | + admin_answer_images_path(answer) %> + +
+ (<%= answer.documents.count rescue 0 %>)
+ + <%= link_to t("admin.questions.show.answers.documents_list"), + admin_answer_documents_path(answer) %> + |
+ + <%= link_to t("admin.questions.show.answers.video_list", + count: answer.videos.count), + admin_answer_videos_path(answer) %> + | <% end %>