demarches-normaliennes/app/controllers/new_administrateur/services_controller.rb

52 lines
1 KiB
Ruby
Raw Normal View History

2018-04-19 16:15:44 +02:00
module NewAdministrateur
class ServicesController < AdministrateurController
def index
@services = services.ordered
2018-04-19 16:15:44 +02:00
end
2018-04-19 10:44:14 +02:00
def new
end
def create
new_service = Service.new(service_params)
new_service.administrateur = current_administrateur
if new_service.save
redirect_to services_path, notice: "#{new_service.nom} créé"
else
flash[:alert] = new_service.errors.full_messages
render :new
end
end
2018-04-19 18:12:48 +02:00
def edit
@service = service
end
def update
@service = service
if @service.update(service_params)
redirect_to services_path, notice: "#{@service.nom} modifié"
else
flash[:alert] = @service.errors.full_messages
render :edit
end
end
2018-04-19 16:15:44 +02:00
private
2018-04-19 10:44:14 +02:00
def service_params
params.require(:service).permit(:nom, :type_organisme)
end
2018-04-19 18:12:48 +02:00
def service
services.find(params[:id])
end
2018-04-19 16:15:44 +02:00
def services
current_administrateur.services
end
end
end