71 lines
1.3 KiB
Ruby
71 lines
1.3 KiB
Ruby
class Admin::DonatorsController < ApplicationController
|
|
layout "admin"
|
|
def index
|
|
@donators = Donator.all
|
|
end
|
|
|
|
def new
|
|
@donator = Donator.new(:date_insc => Date.today)
|
|
@donator.particular = Particular.new
|
|
|
|
end
|
|
|
|
|
|
def create
|
|
@donator = Donator.new(params.require(:donator).permit!)
|
|
|
|
if @donator.save
|
|
redirect_to :action => :index, :notice => "Donateur ajouté avec succès"
|
|
|
|
else
|
|
|
|
render :action => :new
|
|
end
|
|
|
|
|
|
end
|
|
|
|
def edit
|
|
@donator = Donator.find(params[:id])
|
|
end
|
|
|
|
def show
|
|
@donator = Donator.find(params[:id])
|
|
end
|
|
|
|
def update
|
|
@donator = Donator.find(params[:id])
|
|
|
|
if @donator.update_attributes(params.require(:donator).permit!)
|
|
redirect_to :action => :index, :notice => "Donateur modifié avec succès"
|
|
|
|
else
|
|
|
|
render :action => :edit
|
|
end
|
|
|
|
end
|
|
|
|
def destroy
|
|
@donator = Donator.find(params[:id])
|
|
@donator.destroy
|
|
|
|
redirect_to :back
|
|
end
|
|
|
|
def import
|
|
|
|
require 'roo'
|
|
|
|
@xlsx = Roo::Spreadsheet.open("#{Rails.root}/import_donateurs/1.xls")
|
|
#xlsx = Roo::Excelx.new("./new_prices.xlsx")
|
|
|
|
# Use the extension option if the extension is ambiguous.
|
|
#xlsx = Roo::Spreadsheet.open('./rails_temp_upload', extension: :xlsx)
|
|
|
|
@xlsx.info
|
|
@sheet = @xlsx.sheet(0)
|
|
|
|
end
|
|
end
|