Fix attachment appearence after update (#1745)

This commit is contained in:
aignatov-bio 2019-05-13 10:54:16 +02:00 committed by GitHub
parent 837e5d1fea
commit da5b24ef57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 7 deletions

View file

@ -168,15 +168,29 @@ class AssetsController < ApplicationController
# Post process file here
@asset.post_process_file(@asset.team)
render_html = if @asset.step
asset_position = @asset.step.asset_position(@asset)
render_to_string(
partial: 'steps/attachments/item.html.erb',
locals: {
asset: @asset,
i: asset_position[:pos],
assets_count: asset_position[:count],
step: @asset.step
},
formats: :html
)
else
render_to_string(
partial: 'shared/asset_link',
locals: { asset: @asset, display_image_tag: true },
formats: :html
)
end
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: 'shared/asset_link',
locals: { asset: @asset, display_image_tag: true },
formats: :html
)
}
render json: { html: render_html }
end
end
end

View file

@ -124,6 +124,12 @@ class Step < ApplicationRecord
st
end
def asset_position(asset)
assets.order(:file_updated_at).each_with_index do |step_asset, i|
return { count: assets.count, pos: i } if asset.id == step_asset.id
end
end
protected
def cascade_after_destroy