Class: Sibu::ImagesController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#check_site_ownership!, #conf, #sibu_user

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
37
# File 'app/controllers/sibu/images_controller.rb', line 16

def create
  @image = Sibu::Image.new(image_params)
  if @image.save
    if !@page_id.blank? && !@section_id.blank? && !@element_id.blank? && !@size.blank?
      p = Sibu::Page.find(@page_id)
      entity = @entity_type == 'site' ? p.site : p
      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(p.site_id, @page_id), msg
    else
      redirect_to images_url, 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



54
55
56
57
# File 'app/controllers/sibu/images_controller.rb', line 54

def destroy
  @image.destroy
  redirect_to images_url, notice: "L'image a bien été supprimée."
end

#editObject



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

def edit
end

#indexObject



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

def index
  @images = Sibu::Image.for_user(sibu_user)
end

#newObject



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

def new
  @image = Sibu::Image.new(user_id: send(Rails.application.config.sibu[:current_user]).id)
end

#showObject



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

def show
end

#updateObject



45
46
47
48
49
50
51
52
# File 'app/controllers/sibu/images_controller.rb', line 45

def update
  if @image.update(image_params)
    redirect_to images_url, notice: "L'image a bien été mise à jour."
  else
    flash.now[:alert] = "Une erreur s'est produite lors de l'enregistrement de l'image."
    render :index
  end
end