Sha256: 0f23a693c6fdd803952489aa5a0eab448b0e33cd04f8f774fafd6cbf234c1544

Contents?: true

Size: 1.25 KB

Versions: 25

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Admin
  class ImagesController < Admin::AdminController
    before_action :find_image, only: %i[show edit update destroy]

    def index; end

    def show; end

    def new; end

    def edit; end

    def create
      @image = Image.create(image_params)

      respond_to do |format|
        format.json { render_image_json(@image) }
      end
    end

    def update
      @image.update(image_params)
      respond_to do |format|
        format.json { render_image_json(@image) }
      end
    end

    def destroy; end

    protected

    def localized_attributes
      %i[caption alternative]
    end

    def image_params
      params.require(:image).permit(
        :name, :description, :file,
        :crop_start_x, :crop_start_y, :crop_height, :crop_width, :locale,
        :crop_gravity_x, :crop_gravity_y,
        localized_attributes.index_with do |_a|
          I18n.available_locales
        end
      )
    end

    def find_image
      @image = Image.find(params[:id])
    end

    def render_image_json(image)
      if image.valid?
        render json: Admin::ImageResource.new(image)
      else
        render json: { status: "error",
                       error: image.errors.first.full_message }
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/controllers/admin/images_controller.rb
pages_core-3.15.4 app/controllers/admin/images_controller.rb
pages_core-3.15.3 app/controllers/admin/images_controller.rb
pages_core-3.15.2 app/controllers/admin/images_controller.rb
pages_core-3.15.1 app/controllers/admin/images_controller.rb
pages_core-3.14.0 app/controllers/admin/images_controller.rb
pages_core-3.13.0 app/controllers/admin/images_controller.rb
pages_core-3.12.7 app/controllers/admin/images_controller.rb
pages_core-3.12.6 app/controllers/admin/images_controller.rb
pages_core-3.12.5 app/controllers/admin/images_controller.rb
pages_core-3.12.4 app/controllers/admin/images_controller.rb
pages_core-3.12.3 app/controllers/admin/images_controller.rb
pages_core-3.12.2 app/controllers/admin/images_controller.rb
pages_core-3.12.1 app/controllers/admin/images_controller.rb
pages_core-3.12.0 app/controllers/admin/images_controller.rb
pages_core-3.11.3 app/controllers/admin/images_controller.rb
pages_core-3.11.2 app/controllers/admin/images_controller.rb
pages_core-3.11.1 app/controllers/admin/images_controller.rb
pages_core-3.11.0 app/controllers/admin/images_controller.rb
pages_core-3.10.2 app/controllers/admin/images_controller.rb