Move method 'recover_documents_from_cache' from documentable controllers to document.
This commit is contained in:
@@ -22,7 +22,6 @@ class Admin::Poll::QuestionsController < Admin::Poll::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)
|
||||
@@ -39,10 +38,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
|
||||
end
|
||||
|
||||
def update
|
||||
@question.assign_attributes(question_params)
|
||||
recover_documents_from_cache(@question)
|
||||
|
||||
if @question.save
|
||||
if @question.update(question_params)
|
||||
redirect_to admin_question_path(@question), notice: t("flash.actions.save_changes.notice")
|
||||
else
|
||||
render :edit
|
||||
|
||||
@@ -50,7 +50,6 @@ module Budgets
|
||||
|
||||
def create
|
||||
@investment.author = current_user
|
||||
recover_documents_from_cache(@investment)
|
||||
recover_image_from_cache(@investment)
|
||||
|
||||
if @investment.save
|
||||
|
||||
@@ -58,7 +58,6 @@ module CommentableActions
|
||||
|
||||
def update
|
||||
resource.assign_attributes(strong_params)
|
||||
recover_documents_from_cache(resource)
|
||||
recover_image_from_cache(resource)
|
||||
|
||||
if resource.save
|
||||
@@ -113,13 +112,6 @@ module CommentableActions
|
||||
nil
|
||||
end
|
||||
|
||||
def recover_documents_from_cache(resource)
|
||||
return false unless resource.try(:documents)
|
||||
resource.documents = resource.documents.each do |document|
|
||||
document.set_attachment_from_cached_attachment if document.cached_attachment.present?
|
||||
end
|
||||
end
|
||||
|
||||
def recover_image_from_cache(resource)
|
||||
return false unless resource.try(:image)
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ class DocumentsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
recover_attachments_from_cache
|
||||
|
||||
if @document.save
|
||||
flash[:notice] = t "documents.actions.create.notice"
|
||||
redirect_to params[:from]
|
||||
@@ -62,10 +60,4 @@ class DocumentsController < ApplicationController
|
||||
@document.user = current_user
|
||||
end
|
||||
|
||||
def recover_attachments_from_cache
|
||||
if @document.attachment.blank? && @document.cached_attachment.present?
|
||||
@document.set_attachment_from_cached_attachment
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -26,7 +26,6 @@ class ProposalsController < ApplicationController
|
||||
|
||||
def create
|
||||
@proposal = Proposal.new(proposal_params.merge(author: current_user))
|
||||
recover_documents_from_cache(@proposal)
|
||||
recover_image_from_cache(@proposal)
|
||||
|
||||
if @proposal.save
|
||||
|
||||
@@ -21,6 +21,8 @@ class Document < ActiveRecord::Base
|
||||
validates :documentable_id, presence: true, if: -> { persisted? }
|
||||
validates :documentable_type, presence: true, if: -> { persisted? }
|
||||
|
||||
before_save :set_attachment_from_cached_attachment, if: -> { cached_attachment.present? }
|
||||
|
||||
def set_cached_attachment_from_attachment(prefix)
|
||||
self.cached_attachment = if Paperclip::Attachment.default_options[:storage] == :filesystem
|
||||
attachment.path
|
||||
|
||||
Reference in New Issue
Block a user