Class: Backend::ImagesController

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

Instance Method Summary collapse

Methods inherited from BaseController

#breadcrumb, #current_admin, #default_app_locale, #translate_notice

Methods included from Udongo::Cryptography

#crypt

Instance Method Details

#createObject



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

def create
  @image.build_asset
  @image.asset.filename = params[:image][:asset][:filename]
  @image.asset.description = params[:image][:asset][:description]

  if @image.asset.filename && @image.asset.filename.content_type.to_s.include?('image') && @image.save
    redirect_images_overview(:added)
  else
    @image.errors.add :filename, 'Ignore me'
    render :new
  end
end

#indexObject



6
7
8
9
# File 'app/controllers/backend/images_controller.rb', line 6

def index
  @search = Asset.ransack params[:q]
  @assets = @search.result(distinct: true).image.where.not(id: @model.images.pluck(:asset_id)).order('id DESC').limit(30)
end


24
25
26
27
# File 'app/controllers/backend/images_controller.rb', line 24

def link
  @model.images.create(asset: Asset.find(params[:asset_id]))
  redirect_images_overview(:added)
end


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

def unlink
  @model.images.find_by(asset_id: params[:asset_id]).destroy
  redirect_images_overview(:deleted)
end