Sha256: b047cb3229e95273b342815493d8eeb11eb9a6d705e6bca53e826f27ecebc338

Contents?: true

Size: 804 Bytes

Versions: 5

Compression:

Stored size: 804 Bytes

Contents

module Intro
  module Admin
    class ImagesController < ::Intro::Admin::ApplicationController
      if Rails::VERSION::MAJOR > 3
        before_action :authenticate
        before_action :require_image, only: :create
      else
        before_filter :authenticate
        before_filter :require_image, only: :create
      end

      def create
        uploader = Intro::ImageUploader.new

        uploader.cache!(params[:image])
        uploader.store!

        render json: { data: { url: uploader.url } }
      end

      protected

      def require_image
        params[:image].nil? && respond_to do |format|
          format.json { render json: { message: t('intro.errors.require_image') }, status: :bad_request }
          format.any  { head :bad_request  }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
intro-0.4.1 app/controllers/intro/admin/images_controller.rb
intro-0.4.0 app/controllers/intro/admin/images_controller.rb
intro-0.3.0 app/controllers/intro/admin/images_controller.rb
intro-0.2.0 app/controllers/intro/admin/images_controller.rb
intro-0.1.0 app/controllers/intro/admin/images_controller.rb