Sha256: 9c73821e793b969eb031a044c9e091b1bc8ff05bff09eb8fb550452ca139d0f8

Contents?: true

Size: 1.35 KB

Versions: 16

Compression:

Stored size: 1.35 KB

Contents

require_dependency 'notee/application_controller'

module Notee
  class ImagesController < ApplicationController

    def index
      @images = Image.where(is_deleted: false).order(updated_at: :desc)
      render json: { status: 'success', images: @images }
    end

    def show
      @image = Image.find_by(content: params[:search_txt].to_s) if params[:search_txt]
      @image = Image.find_by(id: params[:search_txt].to_i) if params[:search_txt] && !@image
      render json: { status: 'success', image: @image }
    end

    def create
      @image = Image.new
      @image.file = params[:image]
      respond_to do |format|
        if @image.save
          format.json { render json: @image, status: 200 }
        else
          format.json { render json: @image.errors, status: :unprocessable_entity }
        end
      end
    end

    def destroy
      return unless @del_img = Image.find_by(content: params[:name])

      respond_to do |format|
        if @del_img.update(is_deleted: true)
          format.json { render json: @del_img, status: 200 }
        else
          format.json { render json: @del_img.errors, status: :internal_server_error }
        end
      end
    end

    private

    def image_params
      params.require(:image).permit(:title, :content, :slug, :status, :image_id, :thumbnail_id, :published_at, :seo_keyword, :seo_description)
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
notee-1.1.2.4 app/controllers/notee/images_controller.rb
notee-1.1.2.3 app/controllers/notee/images_controller.rb
notee-1.1.2.2 app/controllers/notee/images_controller.rb
notee-1.1.2.1 app/controllers/notee/images_controller.rb
notee-1.1.2 app/controllers/notee/images_controller.rb
notee-1.1.1 app/controllers/notee/images_controller.rb
notee-1.1.0 app/controllers/notee/images_controller.rb
notee-1.0.8 app/controllers/notee/images_controller.rb
notee-1.0.7 app/controllers/notee/images_controller.rb
notee-1.0.6 app/controllers/notee/images_controller.rb
notee-1.0.5 app/controllers/notee/images_controller.rb
notee-1.0.4 app/controllers/notee/images_controller.rb
notee-1.0.3 app/controllers/notee/images_controller.rb
notee-1.0.2 app/controllers/notee/images_controller.rb
notee-1.0.1 app/controllers/notee/images_controller.rb
notee-1.0.0 app/controllers/notee/images_controller.rb