class Admin::ReseauxesController < ApplicationController layout "admin" def index @reseauxes = Reseaux.where(:parent_id => nil).order(:name) end def new @reseaux = Reseaux.new(:parent_id => params[:parent_id]) end def create @reseaux = Reseaux.new(reseaux_params) if @reseaux.save flash[:notice] = "Catégorie créée avec succès." if @reseaux.parent redirect_to admin_reseaux_path(@reseaux.parent_id) else redirect_to admin_reseauxes_path end else render "new" end end def edit @reseaux = Reseaux.find(params[:id]) end def show @reseaux = Reseaux.find(params[:id]) end def update @reseaux = Reseaux.find(params[:id]) if @reseaux.update_attributes(reseaux_params) flash[:notice] = "Catégorie modifiée avec succès." if @reseaux.parent redirect_to admin_reseaux_path(@reseaux.parent_id) else redirect_to admin_reseauxes_path end else render :action => "edit" end end def destroy @reseaux = Reseaux.find(params[:id]) if @reseaux.destroy flash[:notice] = "Reseaux supprimée avec succès." else flash[:error] = "Impossible de supprimer ce reseaux ." end redirect_to :action => :index end def reseaux_params params.require(:reseaux).permit! end end