Class: Articles::CoverImagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/postnhost/articles/cover_images_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/postnhost/articles/cover_images_controller.rb', line 6

def create
  file = params[:file]

  if file.present?
    @article.cover_image = file

    if @article.save
      render json: { url: @article.cover_image.url }, status: :ok
    else
      render json: { error: @article.errors.full_messages.join(", ") }, status: :unprocessable_content
    end
  else
    render json: { error: "No file provided" }, status: :bad_request
  end
end

#destroyObject



22
23
24
25
26
27
# File 'app/controllers/postnhost/articles/cover_images_controller.rb', line 22

def destroy
  # HACK: to bypass carrierwave image removal from bucket to keep the version history
  @article.update_column(:cover_image, nil)

  head :no_content
end