Documents upload for questions working
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
include CommentableActions
|
||||
|
||||
load_and_authorize_resource :poll
|
||||
load_and_authorize_resource :question, class: 'Poll::Question'
|
||||
|
||||
@@ -20,6 +22,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
|
||||
def create
|
||||
@question.author = @question.proposal.try(:author) || current_user
|
||||
recover_documents_from_cache(@question)
|
||||
|
||||
if @question.save
|
||||
redirect_to admin_question_path(@question)
|
||||
@@ -29,6 +32,7 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
end
|
||||
|
||||
def show
|
||||
@document = Document.new(documentable: @question)
|
||||
end
|
||||
|
||||
def edit
|
||||
@@ -54,7 +58,8 @@ class Admin::Poll::QuestionsController < Admin::BaseController
|
||||
private
|
||||
|
||||
def question_params
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers)
|
||||
params.require(:poll_question).permit(:poll_id, :title, :question, :description, :proposal_id, :valid_answers, :video_url,
|
||||
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id])
|
||||
end
|
||||
|
||||
def search_params
|
||||
|
||||
@@ -10,6 +10,8 @@ class Polls::QuestionsController < ApplicationController
|
||||
@comment_tree = CommentTree.new(@commentable, params[:page], @current_order)
|
||||
set_comment_flags(@comment_tree.comments)
|
||||
|
||||
@document = Document.new(documentable: @question)
|
||||
|
||||
question_answer = @question.answers.where(author_id: current_user.try(:id)).first
|
||||
@answers_by_question_id = {@question.id => question_answer.try(:answer)}
|
||||
end
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
class Poll::Question < ActiveRecord::Base
|
||||
include Measurable
|
||||
include Searchable
|
||||
include Documentable
|
||||
documentable max_documents_allowed: 1,
|
||||
max_file_size: 3.megabytes,
|
||||
accepted_content_types: [ "application/pdf" ]
|
||||
accepts_nested_attributes_for :documents, allow_destroy: true
|
||||
|
||||
acts_as_paranoid column: :hidden_at
|
||||
include ActsAsParanoidAliases
|
||||
|
||||
@@ -26,6 +26,17 @@
|
||||
ckeditor: { language: I18n.locale } %>
|
||||
</div>
|
||||
|
||||
<div class="documents small-12" data-max-documents="<%= Poll::Question.max_documents_allowed %>">
|
||||
<%= render 'documents/nested_documents', documentable: @question %>
|
||||
</div>
|
||||
|
||||
<div class="small-12">
|
||||
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>
|
||||
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
|
||||
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false,
|
||||
aria: {describedby: "video-url-help-text"} %>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="actions small-12 medium-4 column margin-top">
|
||||
<%= f.submit(class: "button expanded", value: t("shared.save")) %>
|
||||
|
||||
Reference in New Issue
Block a user