I have some buttons to purge collections so it's easy to restore the website to pristine state during development/test, without even restarting the server.
How can I execute the content of seeds.rb inside a controller action ?
def purge
if Rails.env.production?
should_not_happen(severity: :armageddon)
else
# Well at least restore one admin account !
User.all.each(&:destroy)
regenerate_main_admin_accounts # Here I need to replay the content of `seeds.rb`
redirect_to(admin_dashboard_path)
end
end
Note : the contents of my seeds.rb file make extensive use of conditionals and methods that check for the presence of data, I could run it a billion times there would be no duplicated data in the DB, so I can just run it even if only to restore 1% of what is gone (we're talking dev/test environments here, no time/resource pressure).