Class: Fae::ImagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/fae/images_controller.rb

Instance Method Summary collapse

Instance Method Details

#create_html_embeddedObject

ajax action

Called from the Trumbowyg JS wysiwyg editor when embedding images to a HTML field.



21
22
23
24
# File 'app/controllers/fae/images_controller.rb', line 21

def create_html_embedded
  image = Image.create! asset: params[:image]
  render json: { success: true, file: image.asset.url }
end

#delete_imageObject

ajax delete action

post ‘images/:id/delete_image’ => ‘images#delete_image’, as: :delete_image here we just remove the asset from the attached image model, because if we deleted the model itself, re-uploading a new one would break.



9
10
11
12
13
14
15
# File 'app/controllers/fae/images_controller.rb', line 9

def delete_image
  image = Image.find_by_id(params[:id])
  image.remove_asset = true
  image.save
  CarrierWave.clean_cached_files!
  head :ok
end