Class: Notee::ImagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/notee/images_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#restrict_access_json, #set_request_filter

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/notee/images_controller.rb', line 18

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

#destroyObject



30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/notee/images_controller.rb', line 30

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

#indexObject



7
8
9
10
# File 'app/controllers/notee/images_controller.rb', line 7

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

#showObject



12
13
14
15
16
# File 'app/controllers/notee/images_controller.rb', line 12

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