Sha256: d572abf60081a0f21dcb40f3e42b1da2a9a055d9fbf87665d592a39fc6700b20

Contents?: true

Size: 898 Bytes

Versions: 5

Compression:

Stored size: 898 Bytes

Contents

module LadyJosephine
  class ImagesController < ::ApplicationController

    def create
      image = Image.from_params image_params

      if image && image.save
        response = {file: {url: image.file.url}, versions: sizes_hash(image.file)}
        render json: response.as_json, status: 200
      elsif image
        render json: image.file.errors,  status: 500
      else
        render json: { error: 'Could not save Image.'} ,  status: 500
      end
    end

    private

    def image_params
      params.require(:attachment).permit([:name, :file])
      params.require("block-uuid")
      params.require("article-uuid")
      params.require("model-name")
      params.require("column-name")
      params
    end

    def sizes_hash(image)
      result = {}
      image.versions.each do |version, metadata|
        result[version] = metadata.url
      end
      result
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lady_josephine-0.7.0 app/controllers/lady_josephine/images_controller.rb
lady_josephine-0.6.3 app/controllers/lady_josephine/images_controller.rb
lady_josephine-0.6.2 app/controllers/lady_josephine/images_controller.rb
lady_josephine-0.6.1 app/controllers/lady_josephine/images_controller.rb
lady_josephine-0.6.0 app/controllers/lady_josephine/images_controller.rb