ballalama3_app/app/controllers/admin/realisations_controller.rb
Nicolas Bally bc774b8159 initial
2016-12-01 10:54:16 +01:00

137 lines
2.0 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::RealisationsController < ApplicationController
before_filter :auth_admin
layout "admin"
before_filter :find_realisations
def index
end
def cible
@realisations = Realisation.all
render :layout => false
end
def new
@realisation = Realisation.new()
end
def edit
@realisation = Realisation.find(params[:id])
end
def show
@realisation = Realisation.find(params[:id])
end
def create
@realisation = Realisation.new(params.require(:realisation).permit!)
if @realisation.save
self.find_realisations
flash[:notice] = "La catégorie à été ajouté avec succès."
else
render :action => "new"
end
end
def update
@realisation = Realisation.find(params[:id])
@reorder = true if params[:reorder]
respond_to do |format|
if @realisation.update_attributes(params.require(:realisation).permit!)
#Realisation.all.each do |mi|
# mi.set_permalink
#end
flash[:notice] = "Le menu à été modifié avec succès."
format.html { redirect_to(admin_realisations_path(:parent_id => @realisation.parent_id)) }
if @reorder
format.js {
render :action => "update" }
else
format.js {
@realisation = Realisation.find(@realisation.id)
render :action => "update_row" }
end
else
flash[:error] = "Cet élément de menu n'a pas pu être déplacé. Vérifiez que son lien permanent n'éxiste pas déjà dans l'élément cible."
if @reorder
format.js { render :action => "update_reorder_failled" }
else
format.html { render :action => "edit" }
format.js { render :action => "edit" }
end
end
end
end
def destroy
@realisation = Realisation.find(params[:id])
@realisation.destroy
flash[:notice] = "Le produit à bien été supprimé."
end
protected
def find_realisations
@realisations = Realisation.all
end
end