ballalama3_app/app/controllers/admin/registrants_controller.rb
Nicolas Bally 1a045e278a suite
2017-01-05 11:20:16 +01:00

95 lines
1.5 KiB
Ruby

# -*- encoding : utf-8 -*-
class Admin::RegistrantsController < ApplicationController
before_filter :auth_admin
layout "admin"
before_filter :find_registrants
def index
end
def import
@file = File.open(Rails.root.join('contacts.csv')).read
r = Regexp.new(/\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/)
@emails = @file.scan(r).uniq
@emails.each do |mail|
Registrant.create(:enabled => true, :email => mail)
end
end
def cible
@registrants = Registrant.all
render :layout => false
end
def new
@registrant = Registrant.new
respond_to do |format|
format.js
end
end
def edit
@registrant = Registrant.find(params[:id])
end
def create
@registrant = Registrant.new(params.require(:registrant).permit!)
respond_to do |format|
if @registrant.save
flash[:notice] = "Le lien à été ajouté avec succès."
self.find_registrants
format.js
else
format.html { render :action => "new" }
format.js { render :action => "new" }
end
end
end
def update
@registrant = Registrant.find(params[:id])
respond_to do |format|
if @registrant.update_attributes(params.require(:registrant).permit!)
format.js
else
format.js { render :action => "edit" }
end
end
end
def destroy
@registrant = Registrant.find(params[:id])
@registrant.destroy
respond_to do |format|
format.js
end
end
def find_registrants
@registrants = Registrant.all
end
end