66 lines
1.1 KiB
Ruby
Executable File
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
|
|
@category = Domain.new()
|
|
|
|
end
|
|
|
|
def create
|
|
@category = Domain.new(domain_params)
|
|
|
|
if @category.save
|
|
flash[:notice] = "Catégorie créée avec succès."
|
|
redirect_to admin_domains_path
|
|
else
|
|
|
|
render "new"
|
|
end
|
|
end
|
|
|
|
def edit
|
|
@category = Domain.find(params[:id])
|
|
|
|
end
|
|
|
|
def update
|
|
@category = Domain.find(params[:id])
|
|
if @category.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
|
|
@category = Domain.find(params[:id])
|
|
if @category.destroy
|
|
flash[:notice] = "Catégorie supprimée avec succès."
|
|
else
|
|
flash[:error] = "Impossible de supprimer cette catégorie."
|
|
end
|
|
|
|
render "index"
|
|
end
|
|
|
|
def domain_params
|
|
params.require(:domain).permit(:parent_id, :name)
|
|
end
|
|
|
|
private
|
|
|
|
def build_tree
|
|
|
|
|
|
end
|
|
|
|
end
|