This is a feature I struggled with for quite awhile, so I thought I'd share my solution. The code is actually pretty simple once I got it figured out. Hopefully it will save somebody else some headaches.
To create an easy on-boarding process, I've put a New List form on the front page of Favsi.com. However, creating a list requires the user to be authenticated, so I needed to create a way to retain the user's New List form data through the authentication/registration process, and then post it. Here's a screenshot of the front page: Favsi Front Page Form
- User goes to the front page.
- User fills out the New List form and presses the Create List button.
- If the user is not logged in, they are prompted to login or register.
- User logs in/registers using standard authentication or using the Facebook/Twitter Connect flow.
- Once logged in/registered, the form data from Step 2 gets submitted and the user is redirected to view their published list.
After much Googling, StackOverflowing, and asking Portland Ruby folks there seemed to be 2 possible approaches:
- Once the form is submitted, carry the form data through the login process in hidden fields then submit it once logged in.
- Write the form data to the user's session then retrieve and submit it once logged in.
Since Favsi offers Facebook and Twitter authentication (which routes the users off of Favsi.com) option 2 was the only choice.
The necessary code is in the lists_controller.rb and application_controller.rb files. Liberally commented :)
If you have many actions which need to resubmit this won't work or it would be hard to maintain your code/