Class: Workarea::Admin::CatalogProductImagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/workarea/admin/catalog_product_images_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user, #find_sort, #wrap_in_view_model, wrap_in_view_model

Methods included from Publishing

#allow_publishing!, #allow_publishing?, #set_publishing_options

Methods included from Visiting

#most_visited

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 11

def create
  @image = @product.images.build(params[:image])

  if @image.save
    flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.created')
    redirect_to catalog_product_images_path(@product)
  else
    render :index, status: :unprocessable_entity
  end
end

#destroyObject



53
54
55
56
57
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 53

def destroy
  @product.images.find(params[:id]).destroy
  flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.removed')
  redirect_to catalog_product_images_path(@product)
end

#editObject



22
23
24
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 22

def edit
  @image = @product.images.find(params[:id])
end

#indexObject



7
8
9
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 7

def index
  @images = ProductImagesViewModel.new(@product)
end

#optionsObject



49
50
51
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 49

def options
  @image_options ||= Catalog::Product.autocomplete_image_options(params[:q])
end

#positionsObject



37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 37

def positions
  positions = params.fetch(:order, [])

  @product.images.each do |image|
    image.position = positions.index(image.id.to_s) || 999
  end

  @product.save!

  head :ok
end

#updateObject



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/workarea/admin/catalog_product_images_controller.rb', line 26

def update
  image = @product.images.find(params[:id])

  if image.update_attributes(params[:image])
    flash[:success] = t('workarea.admin.catalog_product_images.flash_messages.updated')
    redirect_to catalog_product_images_path(@product)
  else
    render :index, status: :unprocessable_entity
  end
end