demarches-normaliennes/lib/tasks/admin.rake

28 lines
732 B
Ruby
Raw Normal View History

namespace :admin do
task :create_admin, [:email] => :environment do |t, args|
email = args[:email]
puts "Creating Administration for #{email}"
a = Administration.new(email: email, password: Devise.friendly_token[0,20])
if a.save
puts "#{a.email} created"
else
puts "An error occured : #{a.errors.full_messages}"
end
end
2018-01-03 11:45:19 +01:00
task list: :environment do
puts "All Administrations :"
Administration.all.pluck(:email).each do |a|
puts a
end
end
task :delete_admin, [:email] => :environment do |t, args|
email = args[:email]
puts "Deleting Administration for #{email}"
a = Administration.find_by(email: email)
a.destroy
puts "#{a.email} deleted"
end
end