demarches-normaliennes/app/controllers/administrations_controller.rb

41 lines
1,013 B
Ruby
Raw Normal View History

2016-02-23 16:51:24 +01:00
class AdministrationsController < ApplicationController
include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper
before_action :authenticate_administration!
def index
2016-04-19 10:41:23 +02:00
@admin = Administrateur.new
2016-02-23 16:51:24 +01:00
@admins = smart_listing_create :admins,
2016-04-19 10:41:23 +02:00
Administrateur.all.order(:email),
2016-02-23 16:51:24 +01:00
partial: "administrations/list",
array: true
2016-04-19 10:41:23 +02:00
2016-02-23 16:51:24 +01:00
end
def show
@admin = Administrateur.find(params[:id])
end
def create
admin = Administrateur.new create_administrateur_params
if admin.save
flash.notice = "Administrateur créé"
NewAdminMailer.new_admin_email(admin, params[:administrateur][:password]).deliver_now!
else
flash.alert = admin.errors.full_messages.join('<br>').html_safe
end
redirect_to administrations_path
end
private
def create_administrateur_params
params.require(:administrateur).permit(:email, :password)
end
end