idn_app/app/controllers/admin/realisation_images_controller.rb
Nicolas Bally b5690bc6f2 initial
2016-07-25 15:55:11 +02:00

83 lines
1.6 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::RealisationImagesController < ApplicationController
layout "admin"
def reorder
i = 0
params[:order].each do |realisation_image_id|
i += 1
realisation_image = RealisationImage.find(realisation_image_id)
realisation_image.position = i
realisation_image.save
end
end
def create
@realisation = Realisation.find(params[:realisation_id])
@realisation_images = []
if params[:image_file_ids].kind_of?(Array)
params[:image_file_ids].each do |image_file_id|
image_file = ImageFile.find(image_file_id)
realisation_image = RealisationImage.create(:image_file_id => image_file.id, :title => image_file.name, :description => image_file.description, :realisation_id => @realisation.id )
@realisation_images << realisation_image
end
end
respond_to do |format|
format.js
end
end
def edit
@realisation_image = RealisationImage.find(params[:id])
if request.xhr?
render :layout => false
end
end
def show
end
def update
@realisation_image = RealisationImage.find(params[:id])
respond_to do |format|
if @realisation_image.update_attributes(params.require(:realisation_image).permit!)
format.js
else
format.html { render :action => "edit", :layout => false}
format.js { render :action => "edit" }
end
end
end
def destroy
@realisation_image = RealisationImage.find(params[:id])
@realisation_image.destroy
end
end