Class: Integral::Backend::ImagesController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/integral/backend/images_controller.rb

Overview

Images controller

Instance Method Summary collapse

Instance Method Details

#createObject

POST / Image creation



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/integral/backend/images_controller.rb', line 36

def create
  @image = Image.new(image_params)

  if remote_request?
    if @image.save
      flash.now[:notice] = notification_message('creation_success')
      render json: @image.to_list_item, status: :created
    else
      flash.now[:error] = notification_message('creation_failure')
      head :unprocessable_entity
    end
  else
    if @image.save
      respond_successfully(notification_message('creation_success'), edit_backend_img_path(@image))
    else
      respond_failure(notification_message('creation_failure'), @image, :new)
    end
  end
end

#destroyObject

DELETE /:id



73
74
75
76
77
78
79
80
# File 'app/controllers/integral/backend/images_controller.rb', line 73

def destroy
  if @image.destroy
    respond_successfully(notification_message('delete_success'), backend_img_index_path)
  else
    flash[:error] = notification_message('delete_failure')
    redirect_to backend_img_index_path
  end
end

#editObject

GET /:id/edit Image edit form



58
59
60
# File 'app/controllers/integral/backend/images_controller.rb', line 58

def edit
  add_breadcrumb I18n.t('integral.navigation.edit'), :edit_backend_img_path
end

#indexObject

GET / Lists all images



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/integral/backend/images_controller.rb', line 10

def index
  respond_to do |format|
    format.html do
      set_grid(Integral::Grids::ImagesGrid)
    end

    format.json do
      if params[:gridview].present?
        set_grid(Integral::Grids::ImagesGrid)
        render json: { content: render_to_string(partial: 'integral/backend/images/grid', locals: { grid: @grid }) }
      else
        respond_to_record_selector(Integral::Image)
      end
    end
  end
end

#newObject

GET /new Image creation form



29
30
31
32
# File 'app/controllers/integral/backend/images_controller.rb', line 29

def new
  add_breadcrumb I18n.t('integral.navigation.new'), :new_backend_img_path
  @image = Image.new
end

#updateObject

PUT /:id Updating an image



64
65
66
67
68
69
70
# File 'app/controllers/integral/backend/images_controller.rb', line 64

def update
  if @image.update(image_params)
    respond_successfully(notification_message('edit_success'), backend_img_index_path)
  else
    respond_failure(notification_message('edit_failure'), @image, :edit)
  end
end