Move method 'recover_image_from_cache' from imageable controllers to image.
This commit is contained in:
@@ -8,6 +8,10 @@ App.Imageable =
|
|||||||
$('#nested-image').on 'cocoon:after-remove', (e, item) ->
|
$('#nested-image').on 'cocoon:after-remove', (e, item) ->
|
||||||
$("#new_image_link").removeClass('hide')
|
$("#new_image_link").removeClass('hide')
|
||||||
|
|
||||||
|
$('#nested-image').on 'cocoon:before-insert', (e, nested_image) ->
|
||||||
|
if $(".js-image-attachment").length > 0
|
||||||
|
$(".js-image-attachment").closest('.image').remove()
|
||||||
|
|
||||||
$('#nested-image').on 'cocoon:after-insert', (e, nested_image) ->
|
$('#nested-image').on 'cocoon:after-insert', (e, nested_image) ->
|
||||||
$("#new_image_link").addClass('hide')
|
$("#new_image_link").addClass('hide')
|
||||||
input = $(nested_image).find('.js-image-attachment')
|
input = $(nested_image).find('.js-image-attachment')
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ module Budgets
|
|||||||
|
|
||||||
def create
|
def create
|
||||||
@investment.author = current_user
|
@investment.author = current_user
|
||||||
recover_image_from_cache(@investment)
|
|
||||||
|
|
||||||
if @investment.save
|
if @investment.save
|
||||||
Mailer.budget_investment_created(@investment).deliver_later
|
Mailer.budget_investment_created(@investment).deliver_later
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ class ImagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
recover_attachments_from_cache
|
|
||||||
|
|
||||||
if @image.save
|
if @image.save
|
||||||
flash[:notice] = t "images.actions.create.notice"
|
flash[:notice] = t "images.actions.create.notice"
|
||||||
redirect_to params[:from]
|
redirect_to params[:from]
|
||||||
@@ -62,10 +60,4 @@ class ImagesController < ApplicationController
|
|||||||
@image.user = current_user
|
@image.user = current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def recover_attachments_from_cache
|
|
||||||
if @image.attachment.blank? && @image.cached_attachment.present?
|
|
||||||
@image.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_image_from_cache(@proposal)
|
|
||||||
|
|
||||||
if @proposal.save
|
if @proposal.save
|
||||||
redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal')
|
redirect_to share_proposal_path(@proposal), notice: I18n.t('flash.actions.create.proposal')
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ module DocumentsHelper
|
|||||||
|
|
||||||
def render_attachment(builder, document)
|
def render_attachment(builder, document)
|
||||||
klass = document.errors[:attachment].any? ? "error" : ""
|
klass = document.errors[:attachment].any? ? "error" : ""
|
||||||
klass = document.persisted? ? " hide" : ""
|
klass = document.persisted? || document.cached_attachment.present? ? " hide" : ""
|
||||||
html = builder.label :attachment,
|
html = builder.label :attachment,
|
||||||
t("documents.upload_document"),
|
t("documents.upload_document"),
|
||||||
class: "button hollow #{klass}"
|
class: "button hollow #{klass}"
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ module ImagesHelper
|
|||||||
|
|
||||||
def render_image_attachment(builder, imageable, image)
|
def render_image_attachment(builder, imageable, image)
|
||||||
klass = image.errors[:attachment].any? ? "error" : ""
|
klass = image.errors[:attachment].any? ? "error" : ""
|
||||||
klass = image.persisted? ? " hide" : ""
|
klass = image.persisted? || image.cached_attachment.present? ? " hide" : ""
|
||||||
html = builder.label :attachment,
|
html = builder.label :attachment,
|
||||||
t("images.form.attachment_label"),
|
t("images.form.attachment_label"),
|
||||||
class: "button hollow #{klass}"
|
class: "button hollow #{klass}"
|
||||||
|
|||||||
@@ -27,9 +27,10 @@ class Image < ActiveRecord::Base
|
|||||||
validates :user_id, presence: true
|
validates :user_id, presence: true
|
||||||
validates :imageable_id, presence: true, if: -> { persisted? }
|
validates :imageable_id, presence: true, if: -> { persisted? }
|
||||||
validates :imageable_type, presence: true, if: -> { persisted? }
|
validates :imageable_type, presence: true, if: -> { persisted? }
|
||||||
|
|
||||||
validate :validate_image_dimensions, if: -> { attachment.present? && attachment.dirty? }
|
validate :validate_image_dimensions, if: -> { attachment.present? && attachment.dirty? }
|
||||||
|
|
||||||
|
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
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<%= f.hidden_field :id %>
|
<%= f.hidden_field :id %>
|
||||||
<%= f.hidden_field :user_id, value: current_user.id %>
|
<%= f.hidden_field :user_id, value: current_user.id %>
|
||||||
<%= f.hidden_field :cached_attachment %>
|
<%= f.hidden_field :cached_attachment %>
|
||||||
<%= f.hidden_field :_destroy %>
|
|
||||||
|
|
||||||
<div class="small-12 column title">
|
<div class="small-12 column title">
|
||||||
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
|
<%= f.text_field :title, placeholder: t("images.new.form.title_placeholder") %>
|
||||||
|
|||||||
Reference in New Issue
Block a user