negos_app/app/controllers/admin/domains_controller.rb
Nicolas Bally b8ad9dbc8d suite
2016-05-31 00:05:59 +02:00

66 lines
1.1 KiB
Ruby
Executable File

class Admin::DomainsController < ApplicationController
layout "admin"
before_action :build_tree, only:[:new, :edit, :index]
def index
@domains = Domain.order(:name)
end
def new
@domain = Domain.new()
end
def create
@domain = Domain.new(domain_params)
if @domain.save
flash[:notice] = "Catégorie créée avec succès."
redirect_to admin_domains_path
else
render "new"
end
end
def edit
@domain = Domain.find(params[:id])
end
def update
@domain = Domain.find(params[:id])
if @domain.update_attributes(domain_params)
flash[:notice] = "Catégorie modifiée avec succès."
redirect_to admin_domains_path
else
render :action => "edit"
end
end
def destroy
@domain = Domain.find(params[:id])
if !@domain.superadmin and @domain.destroy
flash[:notice] = "Domaine supprimée avec succès."
else
flash[:error] = "Impossible de supprimer ce domaine."
end
redirect_to :action => :index
end
def domain_params
params.require(:domain).permit(:parent_id, :name)
end
private
def build_tree
end
end