Cyrus
Cyrus

Reputation: 3717

Keeping POST data during sign up with Devise

I might be approaching this problem the wrong way ... so if you have a more elegant solution I'm all ears.

Imagine I'm making a system like Kickstarter. I want my users to be able to specify how much they want to pledge before I ask them to sign up.

Then, if they're not registered I need them to sign up before putting them back in the flow that they would have been on had they just signed in. Devise makes this easy by redirecting a user back to the after_sign_up_path_for which ends up being after_sign_in_path_for by default.

So this will always issue a GET request. But if I have data that I received from the POST with the amount they wanted to pledge, but that's lost.

Is the only way to do this to store that posted data in the session? Or is there a clever way to start creating the pledge record without the user (without needing to run jobs to destroy orphaned pledge records)?

Upvotes: 2

Views: 68

Answers (1)

polarblau
polarblau

Reputation: 17734

I found the approach described in this blog post over at highgroove.com quite interesting in this regard:  http://highgroove.com/articles/2012/10/09/lazy-user-registration-for-rails-apps.html

The basic idea is to always have an anonymous user at hand, even if the current vistor is not registered. Like this you can create e.g. associations as usual and — once the visitor actually does sign–up — you edit the user rather than all associated objects.

If the user does not ever register, you can simply look for abandoned user accounts and delete them including their associations, rather than look for all kind of abandoned models.

Upvotes: 1

Related Questions