Class: Sibu::ImagesController

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

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/sibu/images_controller.rb', line 16

def create
  @image = Sibu::Image.new(image_params)
  if @image.save
    if @page_id && @section_id && @element_id && @size
      entity = @entity_type == 'site' ? @site : Sibu::Page.find(@page_id)
      ids = (@section_id.split('|') + @element_id.split('|')).uniq[0...-1]
      elt = entity.update_element(*ids, {"id" => @img_id, "src" => @image.file_url(@size.to_sym), "alt" => @image.alt})
      if elt.nil?
        msg = {alert: "Une erreur s'est produite lors de la mise à jour de l'image."}
      else
        msg = {notice: "L'image a bien été mise à jour."}
      end
      redirect_to site_page_edit_content_path(@site.id, @page_id), msg
    else
      redirect_to site_images_url(@image.site_id), notice: "L'image a bien été téléchargée."
    end
  else
    flash.now[:alert] = "Une erreur s'est produite lors du téléchargement de l'image."
    render :new
  end
end

#destroyObject



47
48
# File 'app/controllers/sibu/images_controller.rb', line 47

def destroy
end

#editObject



41
42
# File 'app/controllers/sibu/images_controller.rb', line 41

def edit
end

#indexObject



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

def index
  @images = Sibu::Image.where(site_id: params[:site_id])
end

#newObject



12
13
14
# File 'app/controllers/sibu/images_controller.rb', line 12

def new
  @image = Sibu::Image.new(site_id: @site.id)
end

#showObject



38
39
# File 'app/controllers/sibu/images_controller.rb', line 38

def show
end

#updateObject



44
45
# File 'app/controllers/sibu/images_controller.rb', line 44

def update
end