Move method 'recover_documents_from_cache' from documentable controllers to document.

This commit is contained in:
Senén Rodero Rodríguez
2017-09-23 22:16:18 +02:00
parent ce29185b76
commit c22637c349
6 changed files with 3 additions and 23 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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