简体   繁体   中英

Cleaning up partial registrations

I am working on a Rails app where users must fill out two or more screens to register. The registration data is spread across two or three records in two tables.

Of course, users can bail out before registration is complete. This is detectable as null entries in mandatory columns.

What is the "Rails Way" to clean up these partially complete registrations after some reasonable delay (a few hours)?

In case it makes a difference, I'm deploying on Heroku.

I don't know if it's the "rails way", but I think creating a rake task and running it at regular intervals via a cron job would probably suffice for what you describe. If you're into testing, you can even test the rake tasks just like any other code.

Have you considered having a separate table for "in-progress" users? Then chop it up and spread it around when they're finished.

Then you can clean up abandoned users simply by deleting anything in your in-progress table that has an update_at more than a day old; a daily cron job (or scheduler or ...) that runs a rake task can take care of this. This also prevents them from logging in until they're finished as they're not actually users until they finish.

As a side effect, they won't be able to login until they're finished since they're not real users until they've finished. You might need to tweak your current_user handling inside one controller of course.

This sort of approach also means that you can add NOT NULL constraints to your mandatory columns as an extra level of paranoia.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM