0

The problem I'm having is not quite rare, though I can't find any online guidance for this topic :S

I'm having two models: User and Picture A User can have up to 10 pictures and a picture belongs to one user.

Now I want an input form for creating a user. Though one requirement is that the user shall have selected a minimum of X pictures. I want to upload the pictures via AJAX while the user is filling out the form. This is why I need the id of the user before he actually clicked "Submit" on the form. The picture model needs it to bind the single picture to the user in the database.

I thought about creating an empty User if a single file is accessing the users#create method, but validating wouldn't take place and if the new user just leaves the site without registering, the pictures would last with an empty account.

Thanks in advance!

1 Answer 1

1

I think you'd better tackle it another way. I don't think you want to start creating "empty" User records. Just going to make life messy.

Why not upload the photos, set their user to nil, but track their id's in the session. Once the user hits submit on the form, create the user record, and update the user_id attribute of the photos you know about.

If the user bails out on you, have a periodic task that looks for photos with no user that are older than say 1 day and remove them.

Sign up to request clarification or add additional context in comments.

1 Comment

So simple so good. Thanks :-) Gonna accept the answer tomorow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.