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